@@ -50,6 +50,10 @@ status:
5050 status: Synced
5151 health:
5252 status: Healthy
53+ operationState:
54+ phase: Succeeded
55+ startedAt: "2025-01-29T08:42:34Z"
56+ finishedAt: "2025-01-29T08:42:35Z"
5357`
5458
5559const fakeApp2 = `
@@ -453,6 +457,31 @@ func assertMetricsNotPrinted(t *testing.T, expectedLines, body string) {
453457 }
454458}
455459
460+ func TestMetricsSyncDuration (t * testing.T ) {
461+ cancel , appLister := newFakeLister ()
462+ defer cancel ()
463+ metricsServ , err := NewMetricsServer ("localhost:8082" , appLister , appFilter , noOpHealthCheck , []string {}, []string {})
464+ require .NoError (t , err )
465+
466+ appSyncDurationTotal := `
467+ # HELP argocd_app_sync_duration_seconds_total Application sync performance in seconds total.
468+ # TYPE argocd_app_sync_duration_seconds_total counter
469+ argocd_app_sync_duration_seconds_total{dest_server="https://localhost:6443",name="my-app",namespace="argocd",project="important-project"} 1
470+ `
471+
472+ fakeApp := newFakeApp (fakeApp )
473+ metricsServ .IncAppSyncDuration (fakeApp , fakeApp .Status .OperationState )
474+
475+ req , err := http .NewRequest (http .MethodGet , "/metrics" , nil )
476+ require .NoError (t , err )
477+ rr := httptest .NewRecorder ()
478+ metricsServ .Handler .ServeHTTP (rr , req )
479+ assert .Equal (t , http .StatusOK , rr .Code )
480+ body := rr .Body .String ()
481+ log .Println (body )
482+ assertMetricsPrinted (t , appSyncDurationTotal , body )
483+ }
484+
456485func TestReconcileMetrics (t * testing.T ) {
457486 cancel , appLister := newFakeLister ()
458487 defer cancel ()
0 commit comments