Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
ae1b2782
Commit
ae1b2782
authored
Jan 30, 2020
by
Janos Guljas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add metrics package test
parent
473fb58f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
metrics_test.go
pkg/metrics/metrics_test.go
+59
-0
No files found.
pkg/metrics/metrics_test.go
0 → 100644
View file @
ae1b2782
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
metrics_test
import
(
"strings"
"testing"
"github.com/ethersphere/bee/pkg/metrics"
"github.com/prometheus/client_golang/prometheus"
)
func
TestPrometheusCollectorsFromFields
(
t
*
testing
.
T
)
{
s
:=
newService
()
collectors
:=
metrics
.
PrometheusCollectorsFromFields
(
s
)
if
l
:=
len
(
collectors
);
l
!=
2
{
t
.
Fatalf
(
"got %v collectors %+v, want 2"
,
l
,
collectors
)
}
m1
:=
collectors
[
0
]
.
(
prometheus
.
Metric
)
.
Desc
()
.
String
()
if
!
strings
.
Contains
(
m1
,
"api_request_count"
)
{
t
.
Errorf
(
"unexpected metric %s"
,
m1
)
}
m2
:=
collectors
[
1
]
.
(
prometheus
.
Metric
)
.
Desc
()
.
String
()
if
!
strings
.
Contains
(
m2
,
"api_response_duration_seconds"
)
{
t
.
Errorf
(
"unexpected metric %s"
,
m2
)
}
}
type
service
struct
{
// valid metrics
RequestCount
prometheus
.
Counter
ResponseDuration
prometheus
.
Histogram
// invalid metrics
unexportedCount
prometheus
.
Counter
UninitializedCount
prometheus
.
Counter
}
func
newService
()
*
service
{
return
&
service
{
RequestCount
:
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"api_request_count"
,
Help
:
"Number of API requests."
,
}),
ResponseDuration
:
prometheus
.
NewHistogram
(
prometheus
.
HistogramOpts
{
Name
:
"api_response_duration_seconds"
,
Help
:
"Histogram of API response durations."
,
Buckets
:
[]
float64
{
0.01
,
0.1
,
0.25
,
0.5
,
1
,
2.5
,
5
,
10
},
}),
unexportedCount
:
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"api_unexported_count"
,
Help
:
"This metrics should not be discoverable by metrics.PrometheusCollectorsFromFields."
,
}),
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment