Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
telegraf-nftables
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Due to inactivity, this project is scheduled to be deleted on 2035-04-24.
Why is this scheduled?
Show more breadcrumbs
vqgroup
telegraf-nftables
Commits
73372872
Commit
73372872
authored
7 years ago
by
Trevor Pounds
Committed by
Daniel Nelson
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix panic in statsd p100 calculation (#3230)
parent
103ae3b7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/inputs/statsd/running_stats.go
+10
-3
10 additions, 3 deletions
plugins/inputs/statsd/running_stats.go
plugins/inputs/statsd/running_stats_test.go
+18
-0
18 additions, 0 deletions
plugins/inputs/statsd/running_stats_test.go
with
28 additions
and
3 deletions
plugins/inputs/statsd/running_stats.go
+
10
−
3
View file @
73372872
...
@@ -110,8 +110,15 @@ func (rs *RunningStats) Percentile(n int) float64 {
...
@@ -110,8 +110,15 @@ func (rs *RunningStats) Percentile(n int) float64 {
}
}
i
:=
int
(
float64
(
len
(
rs
.
perc
))
*
float64
(
n
)
/
float64
(
100
))
i
:=
int
(
float64
(
len
(
rs
.
perc
))
*
float64
(
n
)
/
float64
(
100
))
if
i
<
0
{
return
rs
.
perc
[
clamp
(
i
,
0
,
len
(
rs
.
perc
)
-
1
)]
i
=
0
}
func
clamp
(
i
int
,
min
int
,
max
int
)
int
{
if
i
<
min
{
return
min
}
if
i
>
max
{
return
max
}
}
return
rs
.
perc
[
i
]
return
i
}
}
This diff is collapsed.
Click to expand it.
plugins/inputs/statsd/running_stats_test.go
+
18
−
0
View file @
73372872
...
@@ -23,12 +23,18 @@ func TestRunningStats_Single(t *testing.T) {
...
@@ -23,12 +23,18 @@ func TestRunningStats_Single(t *testing.T) {
if
rs
.
Lower
()
!=
10.1
{
if
rs
.
Lower
()
!=
10.1
{
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Lower
())
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Lower
())
}
}
if
rs
.
Percentile
(
100
)
!=
10.1
{
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Percentile
(
100
))
}
if
rs
.
Percentile
(
90
)
!=
10.1
{
if
rs
.
Percentile
(
90
)
!=
10.1
{
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Percentile
(
90
))
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Percentile
(
90
))
}
}
if
rs
.
Percentile
(
50
)
!=
10.1
{
if
rs
.
Percentile
(
50
)
!=
10.1
{
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Percentile
(
50
))
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Percentile
(
50
))
}
}
if
rs
.
Percentile
(
0
)
!=
10.1
{
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Percentile
(
0
))
}
if
rs
.
Count
()
!=
1
{
if
rs
.
Count
()
!=
1
{
t
.
Errorf
(
"Expected %v, got %v"
,
1
,
rs
.
Count
())
t
.
Errorf
(
"Expected %v, got %v"
,
1
,
rs
.
Count
())
}
}
...
@@ -58,12 +64,18 @@ func TestRunningStats_Duplicate(t *testing.T) {
...
@@ -58,12 +64,18 @@ func TestRunningStats_Duplicate(t *testing.T) {
if
rs
.
Lower
()
!=
10.1
{
if
rs
.
Lower
()
!=
10.1
{
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Lower
())
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Lower
())
}
}
if
rs
.
Percentile
(
100
)
!=
10.1
{
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Percentile
(
100
))
}
if
rs
.
Percentile
(
90
)
!=
10.1
{
if
rs
.
Percentile
(
90
)
!=
10.1
{
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Percentile
(
90
))
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Percentile
(
90
))
}
}
if
rs
.
Percentile
(
50
)
!=
10.1
{
if
rs
.
Percentile
(
50
)
!=
10.1
{
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Percentile
(
50
))
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Percentile
(
50
))
}
}
if
rs
.
Percentile
(
0
)
!=
10.1
{
t
.
Errorf
(
"Expected %v, got %v"
,
10.1
,
rs
.
Percentile
(
0
))
}
if
rs
.
Count
()
!=
4
{
if
rs
.
Count
()
!=
4
{
t
.
Errorf
(
"Expected %v, got %v"
,
4
,
rs
.
Count
())
t
.
Errorf
(
"Expected %v, got %v"
,
4
,
rs
.
Count
())
}
}
...
@@ -93,12 +105,18 @@ func TestRunningStats(t *testing.T) {
...
@@ -93,12 +105,18 @@ func TestRunningStats(t *testing.T) {
if
rs
.
Lower
()
!=
5
{
if
rs
.
Lower
()
!=
5
{
t
.
Errorf
(
"Expected %v, got %v"
,
5
,
rs
.
Lower
())
t
.
Errorf
(
"Expected %v, got %v"
,
5
,
rs
.
Lower
())
}
}
if
rs
.
Percentile
(
100
)
!=
45
{
t
.
Errorf
(
"Expected %v, got %v"
,
45
,
rs
.
Percentile
(
100
))
}
if
rs
.
Percentile
(
90
)
!=
32
{
if
rs
.
Percentile
(
90
)
!=
32
{
t
.
Errorf
(
"Expected %v, got %v"
,
32
,
rs
.
Percentile
(
90
))
t
.
Errorf
(
"Expected %v, got %v"
,
32
,
rs
.
Percentile
(
90
))
}
}
if
rs
.
Percentile
(
50
)
!=
11
{
if
rs
.
Percentile
(
50
)
!=
11
{
t
.
Errorf
(
"Expected %v, got %v"
,
11
,
rs
.
Percentile
(
50
))
t
.
Errorf
(
"Expected %v, got %v"
,
11
,
rs
.
Percentile
(
50
))
}
}
if
rs
.
Percentile
(
0
)
!=
5
{
t
.
Errorf
(
"Expected %v, got %v"
,
5
,
rs
.
Percentile
(
0
))
}
if
rs
.
Count
()
!=
16
{
if
rs
.
Count
()
!=
16
{
t
.
Errorf
(
"Expected %v, got %v"
,
4
,
rs
.
Count
())
t
.
Errorf
(
"Expected %v, got %v"
,
4
,
rs
.
Count
())
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment