mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
* [go components] Fixed "go test ./..." in various components Tool: gitpod/catfood.gitpod.cloud * [go components] Update k8s 0.29.3 -> 0.30.9 API - update the go-update-wc-deps.sh script to handle the brunt of that transition - fixes Maintenance- + Subscriber-Controller - document steps Tool: gitpod/catfood.gitpod.cloud * [ws-manager-mk2] Decide how to apply appamor config based on serverversion to support k8s 1.30+ Tool: gitpod/catfood.gitpod.cloud * [gpctl] Missing go mod tidy Tool: gitpod/catfood.gitpod.cloud * Replace vulnerable outcaste-io/badger/v3 with original dgraph-io/badger/v3 Tool: gitpod/catfood.gitpod.cloud * more go mod tidy Tool: gitpod/catfood.gitpod.cloud * [image-builder-bob, installer] Select the correct version of containerd.... Tool: gitpod/catfood.gitpod.cloud --------- Co-authored-by: Gero Posmyk-Leinemann <gero@gitpod.io>
98 lines
2.5 KiB
Go
98 lines
2.5 KiB
Go
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
|
|
// Licensed under the GNU Affero General Public License (AGPL).
|
|
// See License.AGPL.txt in the project root for license information.
|
|
|
|
package metrics
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/google/go-cmp/cmp/cmpopts"
|
|
|
|
dto "github.com/prometheus/client_model/go"
|
|
)
|
|
|
|
func TestAggregatedHistograms(t *testing.T) {
|
|
labelName := "grpc_method"
|
|
lowBound := .005
|
|
midBound := .01
|
|
highBound := .025
|
|
agg := NewAggregatedHistograms(
|
|
"grpc_server_handling_seconds",
|
|
"help",
|
|
[]string{labelName},
|
|
[]float64{lowBound, midBound, highBound},
|
|
)
|
|
labelValue := "foo"
|
|
var count uint64 = 1
|
|
sum := 0.004
|
|
var lowCount uint64 = 1
|
|
var midCount uint64 = 1
|
|
var highCount uint64 = 1
|
|
assertDiff := func() string {
|
|
var actual []*dto.Metric
|
|
for _, m := range agg.collect() {
|
|
dto := &dto.Metric{}
|
|
err := m.Write(dto)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
actual = append(actual, dto)
|
|
}
|
|
|
|
return cmp.Diff([]*dto.Metric{{
|
|
Label: []*dto.LabelPair{{
|
|
Name: &labelName,
|
|
Value: &labelValue,
|
|
}},
|
|
Histogram: &dto.Histogram{
|
|
SampleCount: &count,
|
|
SampleSum: &sum,
|
|
Bucket: []*dto.Bucket{
|
|
{CumulativeCount: &lowCount, UpperBound: &lowBound},
|
|
{CumulativeCount: &midCount, UpperBound: &midBound},
|
|
{CumulativeCount: &highCount, UpperBound: &highBound},
|
|
},
|
|
},
|
|
}}, actual, cmpopts.IgnoreUnexported(dto.Metric{}, dto.LabelPair{}, dto.Histogram{}, dto.Bucket{}))
|
|
}
|
|
|
|
_ = agg.Add([]string{"foo"}, 1, 0.004, []uint64{1, 1, 1})
|
|
if diff := assertDiff(); diff != "" {
|
|
t.Errorf("unexpected output (-want +got):\n%s", diff)
|
|
}
|
|
|
|
// invalid buckets
|
|
_ = agg.Add([]string{"foo"}, 1, 0.004, []uint64{})
|
|
if diff := assertDiff(); diff != "" {
|
|
t.Errorf("unexpected output (-want +got):\n%s", diff)
|
|
}
|
|
|
|
// invalid labels
|
|
_ = agg.Add([]string{"foo", "bar"}, 1, 0.004, []uint64{1, 1, 1})
|
|
if diff := assertDiff(); diff != "" {
|
|
t.Errorf("unexpected output (-want +got):\n%s", diff)
|
|
}
|
|
|
|
count = count + 5
|
|
sum = sum + 0.015
|
|
lowCount = lowCount + 5
|
|
midCount = midCount + 5
|
|
highCount = highCount + 5
|
|
_ = agg.Add([]string{"foo"}, 5, 0.015, []uint64{5, 5, 5})
|
|
if diff := assertDiff(); diff != "" {
|
|
t.Errorf("unexpected output (-want +got):\n%s", diff)
|
|
}
|
|
|
|
count = count + 20
|
|
sum = sum + 0.4700000000000003
|
|
lowCount = lowCount + 5
|
|
midCount = midCount + 10
|
|
highCount = highCount + 15
|
|
_ = agg.Add([]string{"foo"}, 20, 0.4700000000000003, []uint64{5, 10, 15})
|
|
if diff := assertDiff(); diff != "" {
|
|
t.Errorf("unexpected output (-want +got):\n%s", diff)
|
|
}
|
|
}
|