mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-20 17:58:02 +02:00
[management] fix github run id (#3705)
This commit is contained in:
parent
f686615876
commit
1a6d6b3109
2
.github/workflows/golang-test-linux.yml
vendored
2
.github/workflows/golang-test-linux.yml
vendored
@ -482,7 +482,7 @@ jobs:
|
|||||||
go test -tags=benchmark \
|
go test -tags=benchmark \
|
||||||
-run=^$ \
|
-run=^$ \
|
||||||
-bench=. \
|
-bench=. \
|
||||||
-exec 'sudo --preserve-env=CI,NETBIRD_STORE_ENGINE,GIT_BRANCH' \
|
-exec 'sudo --preserve-env=CI,NETBIRD_STORE_ENGINE,GIT_BRANCH,GITHUB_RUN_ID' \
|
||||||
-timeout 20m ./management/...
|
-timeout 20m ./management/...
|
||||||
|
|
||||||
api_integration_test:
|
api_integration_test:
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus/push"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
@ -150,3 +151,28 @@ func BenchmarkDeleteUsers(b *testing.B) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
exitCode := m.Run()
|
||||||
|
|
||||||
|
if exitCode == 0 && os.Getenv("CI") == "true" {
|
||||||
|
runID := os.Getenv("GITHUB_RUN_ID")
|
||||||
|
storeEngine := os.Getenv("NETBIRD_STORE_ENGINE")
|
||||||
|
err := push.New("http://localhost:9091", "api_benchmark").
|
||||||
|
Collector(testing_tools.BenchmarkDuration).
|
||||||
|
Grouping("ci_run", runID).
|
||||||
|
Grouping("store_engine", storeEngine).
|
||||||
|
Push()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to push metrics: %v", err)
|
||||||
|
} else {
|
||||||
|
time.Sleep(1 * time.Minute)
|
||||||
|
_ = push.New("http://localhost:9091", "api_benchmark").
|
||||||
|
Grouping("ci_run", runID).
|
||||||
|
Grouping("store_engine", storeEngine).
|
||||||
|
Delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Exit(exitCode)
|
||||||
|
}
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
|
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/push"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
|
|
||||||
@ -75,6 +74,14 @@ const (
|
|||||||
OperationGetAll = "get_all"
|
OperationGetAll = "get_all"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var BenchmarkDuration = prometheus.NewGaugeVec(
|
||||||
|
prometheus.GaugeOpts{
|
||||||
|
Name: "benchmark_duration_ms",
|
||||||
|
Help: "Benchmark duration per op in ms",
|
||||||
|
},
|
||||||
|
[]string{"module", "operation", "test_case", "branch"},
|
||||||
|
)
|
||||||
|
|
||||||
type TB interface {
|
type TB interface {
|
||||||
Cleanup(func())
|
Cleanup(func())
|
||||||
Helper()
|
Helper()
|
||||||
@ -324,38 +331,15 @@ func EvaluateBenchmarkResults(b *testing.B, testCase string, duration time.Durat
|
|||||||
b.Fatalf("environment variable GIT_BRANCH is not set")
|
b.Fatalf("environment variable GIT_BRANCH is not set")
|
||||||
}
|
}
|
||||||
|
|
||||||
storeEngine := os.Getenv("NETBIRD_STORE_ENGINE")
|
|
||||||
if storeEngine == "" {
|
|
||||||
b.Fatalf("environment variable NETBIRD_STORE_ENGINE is not set")
|
|
||||||
}
|
|
||||||
|
|
||||||
if recorder.Code != http.StatusOK {
|
if recorder.Code != http.StatusOK {
|
||||||
b.Fatalf("Benchmark %s failed: unexpected status code %d", testCase, recorder.Code)
|
b.Fatalf("Benchmark %s failed: unexpected status code %d", testCase, recorder.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
msPerOp := float64(duration.Nanoseconds()) / float64(b.N) / 1e6
|
msPerOp := float64(duration.Nanoseconds()) / float64(b.N) / 1e6
|
||||||
|
|
||||||
gauge := prometheus.NewGauge(prometheus.GaugeOpts{
|
gauge := BenchmarkDuration.WithLabelValues(module, operation, testCase, branch)
|
||||||
Name: "benchmark_duration_ms",
|
|
||||||
Help: "Benchmark duration per op in ms",
|
|
||||||
ConstLabels: prometheus.Labels{
|
|
||||||
"store_engine": storeEngine,
|
|
||||||
"module": module,
|
|
||||||
"operation": operation,
|
|
||||||
"test_case": testCase,
|
|
||||||
"branch": branch,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
gauge.Set(msPerOp)
|
gauge.Set(msPerOp)
|
||||||
|
|
||||||
if err := push.New("http://localhost:9091", "api_benchmark").
|
|
||||||
Collector(gauge).
|
|
||||||
Grouping("ci_run", os.Getenv("GITHUB_RUN_ID")).
|
|
||||||
Push(); err != nil {
|
|
||||||
b.Fatalf("Could not push benchmark metric: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
b.ReportMetric(msPerOp, "ms/op")
|
b.ReportMetric(msPerOp, "ms/op")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user