Files
deploy/reposerver/metrics/metrics_test.go
zeekayandHanzo Dev 84ee9fa0ce cd: kill the argo naming — binaries, packages, identifiers
Every command is cd-*: cd, cd-server, cd-repo-server,
cd-application-controller, cd-applicationset-controller, cd-cmp-server,
cd-commit-server, cd-dex, cd-git-ask-pass, cd-k8s-auth, cd-notification.
util/argo is util/cd; util/notification/argocd is util/notification/cd.

Preserved deliberately: github.com/argoproj/argocd-example-apps is an
EXTERNAL repo used as an e2e fixture, and notifications-engine + pkg/v2 are
real dependencies. Renaming a URL we do not own would break the tests.

Two bugs I made and caught, both from a careless sed:
- s/argo/cd/g turned 'argocd' into 'cdcd' in two directory names
- renaming the package declaration left every call site saying argo.X

go build ./... exit 0.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-28 16:00:25 -07:00

48 lines
1.9 KiB
Go

package metrics
import (
"strings"
"testing"
"time"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestObserveParallelismWaitDuration(t *testing.T) {
t.Parallel()
m := NewMetricsServer()
m.ObserveParallelismWaitDuration(50 * time.Millisecond)
m.ObserveParallelismWaitDuration(3 * time.Second)
m.ObserveParallelismWaitDuration(75 * time.Second)
expected := `
# HELP cd_repo_parallelism_wait_duration_seconds Time spent waiting for the repo-server manifest generation parallelism semaphore. Observed on every acquire attempt, including those that fail (e.g. context canceled).
# TYPE cd_repo_parallelism_wait_duration_seconds histogram
cd_repo_parallelism_wait_duration_seconds_bucket{le="0.1"} 1
cd_repo_parallelism_wait_duration_seconds_bucket{le="0.25"} 1
cd_repo_parallelism_wait_duration_seconds_bucket{le="0.5"} 1
cd_repo_parallelism_wait_duration_seconds_bucket{le="1"} 1
cd_repo_parallelism_wait_duration_seconds_bucket{le="2"} 1
cd_repo_parallelism_wait_duration_seconds_bucket{le="4"} 2
cd_repo_parallelism_wait_duration_seconds_bucket{le="10"} 2
cd_repo_parallelism_wait_duration_seconds_bucket{le="20"} 2
cd_repo_parallelism_wait_duration_seconds_bucket{le="60"} 2
cd_repo_parallelism_wait_duration_seconds_bucket{le="120"} 3
cd_repo_parallelism_wait_duration_seconds_bucket{le="+Inf"} 3
cd_repo_parallelism_wait_duration_seconds_sum 78.05
cd_repo_parallelism_wait_duration_seconds_count 3
`
err := testutil.GatherAndCompare(m.PrometheusRegistry, strings.NewReader(expected), "cd_repo_parallelism_wait_duration_seconds")
require.NoError(t, err)
}
func TestParallelismWaitMetricRegistered(t *testing.T) {
t.Parallel()
m := NewMetricsServer()
count := testutil.CollectAndCount(m.PrometheusRegistry, "cd_repo_parallelism_wait_duration_seconds")
assert.Equal(t, 1, count)
}