Files
graphql-monitoring-proxy/monitoring/helpers_bench_test.go
T
lukaszraczylo 2e40ee0c62 Update the helpers to sort labels alpabetically.
It will help to avoid the flaky tests and duplicated metrics.

As a bonus - added tests and benchmarks for monitoring package.
2024-06-11 19:57:18 +01:00

45 lines
919 B
Go

package libpack_monitoring
import (
"testing"
libpack_config "github.com/lukaszraczylo/graphql-monitoring-proxy/config"
)
func BenchmarkGetMetricsName(b *testing.B) {
// Setup environment
libpack_config.PKG_NAME = "test_service"
ms := &MetricsSetup{metrics_prefix: "test_prefix"}
labels := map[string]string{
"env": "production",
"region": "us-west-2",
}
// Run the benchmark
for n := 0; n < b.N; n++ {
ms.get_metrics_name("request_count", labels)
}
}
func BenchmarkCompileMetricsWithLabels(b *testing.B) {
labels := map[string]string{
"env": "production",
"region": "us-west-2",
"app": "api-server",
}
for n := 0; n < b.N; n++ {
compile_metrics_with_labels("request_count", labels)
}
}
func BenchmarkValidateMetricsName(b *testing.B) {
input := "valid metric name with special chars @#! and underscores__"
for n := 0; n < b.N; n++ {
validate_metrics_name(input)
}
}