Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e2c5514

Browse files
committedFeb 3, 2025·
fix: latency calculation in check
1 parent 85a43a6 commit e2c5514

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed
 

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ require (
1212
github.com/RaveNoX/go-jsonmerge v1.0.0
1313
github.com/TomOnTime/utfutil v0.0.0-20230223141146-125e65197b36
1414
github.com/WinterYukky/gorm-extra-clause-plugin v0.2.0
15-
github.com/asecurityteam/rolling v2.0.4+incompatible
1615
github.com/aws/aws-sdk-go-v2 v1.31.0
1716
github.com/aws/aws-sdk-go-v2/config v1.27.36
1817
github.com/aws/aws-sdk-go-v2/credentials v1.17.34
@@ -70,6 +69,7 @@ require (
7069
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
7170
golang.org/x/oauth2 v0.23.0
7271
golang.org/x/sync v0.10.0
72+
gonum.org/v1/gonum v0.15.1
7373
google.golang.org/api v0.198.0
7474
google.golang.org/grpc v1.66.2
7575
gopkg.in/yaml.v2 v2.4.0

‎go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew
111111
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
112112
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
113113
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
114-
github.com/asecurityteam/rolling v2.0.4+incompatible h1:WOSeokINZT0IDzYGc5BVcjLlR9vPol08RvI2GAsmB0s=
115-
github.com/asecurityteam/rolling v2.0.4+incompatible/go.mod h1:2D4ba5ZfYCWrIMleUgTvc8pmLExEuvu3PDwl+vnG58Q=
116114
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
117115
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
118116
github.com/aws/aws-sdk-go-v2 v1.31.0 h1:3V05LbxTSItI5kUqNwhJrrrY1BAXxXt0sN0l72QmG5U=
@@ -1139,6 +1137,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
11391137
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
11401138
golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9 h1:LLhsEBxRTBLuKlQxFBYUOU8xyFgXv6cOTp2HASDlsDk=
11411139
golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
1140+
gonum.org/v1/gonum v0.15.1 h1:FNy7N6OUZVUaWG9pTiD+jlhdQ3lMP+/LcTpJ6+a8sQ0=
1141+
gonum.org/v1/gonum v0.15.1/go.mod h1:eZTZuRFrzu5pcyjN5wJhcIhnUdNijYxX1T2IcrOGY0o=
11421142
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
11431143
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
11441144
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=

‎query/check_details.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
"strings"
77
"time"
88

9-
"github.com/asecurityteam/rolling"
109
"github.com/flanksource/commons/duration"
1110
"github.com/flanksource/duty/context"
1211
"github.com/flanksource/duty/types"
1312
"github.com/samber/lo"
13+
"gonum.org/v1/gonum/stat"
1414
)
1515

1616
// Default search window
@@ -137,7 +137,7 @@ func (q CheckQueryParams) ExecuteDetails(ctx context.Context) ([]Timeseries, typ
137137
end := q.GetEndTime().Format(time.RFC3339)
138138

139139
query := `
140-
With grouped_by_window AS (
140+
WITH grouped_by_window AS (
141141
SELECT
142142
duration,
143143
status,
@@ -172,7 +172,7 @@ ORDER BY time
172172
args = []any{start, end, q.Check}
173173
}
174174
uptime := types.Uptime{}
175-
latencies := rolling.NewPointPolicy(rolling.NewWindow(100))
175+
var latencies []float64
176176

177177
rows, err := ctx.Pool().Query(ctx, query, args...)
178178
if err != nil {
@@ -189,15 +189,15 @@ ORDER BY time
189189
}
190190
uptime.Failed += datapoint.Failed
191191
uptime.Passed += datapoint.Passed
192-
latencies.Append(float64(datapoint.Duration))
192+
latencies = append(latencies, float64(datapoint.Duration))
193193
datapoint.Time = ts.Format(time.RFC3339)
194194
results = append(results, datapoint)
195195
}
196196

197197
latency := types.Latency{
198-
Percentile99: latencies.Reduce(rolling.Percentile(99)),
199-
Percentile97: latencies.Reduce(rolling.Percentile(97)),
200-
Percentile95: latencies.Reduce(rolling.Percentile(95)),
198+
Percentile99: stat.Quantile(0.99, stat.Empirical, latencies, nil),
199+
Percentile97: stat.Quantile(0.97, stat.Empirical, latencies, nil),
200+
Percentile95: stat.Quantile(0.95, stat.Empirical, latencies, nil),
201201
}
202202

203203
return results, uptime, latency, nil

0 commit comments

Comments
 (0)
Please sign in to comment.