This repository has been archived by the owner on Oct 2, 2022. It is now read-only.
generated from ContainerSSH/library-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This release adds a `WithLabel` method to create metrics primed with certain labels. This can be used when passing labels between modules.
- Loading branch information
Janos Pasztor
authored
Dec 29, 2020
1 parent
befe233
commit e923fd7
Showing
12 changed files
with
225 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package metrics_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/containerssh/metrics" | ||
) | ||
|
||
func TestGauge(t *testing.T) { | ||
collector := metrics.New(&geoIpLookupProvider{}) | ||
gauge, err := collector.CreateGauge("test", "seconds", "Hello world!") | ||
assert.Nil(t, err, "creating counter returned an error") | ||
|
||
gauge.Set(42) | ||
|
||
testMetrics := collector.GetMetric("test") | ||
assert.Equal(t, 1, len(testMetrics)) | ||
assert.Equal(t, 0, len(testMetrics[0].Labels)) | ||
assert.Equal(t, float64(42), testMetrics[0].Value) | ||
|
||
newGauge := gauge.WithLabels(metrics.Label("foo", "bar")) | ||
newGauge.Set(43) | ||
|
||
testMetrics = collector.GetMetric("test") | ||
assert.Equal(t, 2, len(testMetrics)) | ||
assert.Equal(t, 0, len(testMetrics[0].Labels)) | ||
assert.Equal(t, 1, len(testMetrics[1].Labels)) | ||
assert.Equal(t, float64(42), testMetrics[0].Value) | ||
assert.Equal(t, float64(43), testMetrics[1].Value) | ||
} |
Oops, something went wrong.