-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat: adds various OCI metrics #25493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
reggie-k
merged 10 commits into
argoproj:master
from
ppapapetrou76:issue-25378-oci-request-metrics
Dec 8, 2025
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e6d93c3
adds various OCI metrics
ppapapetrou76 754dbcf
makes linter happy
ppapapetrou76 8195c33
remove unwanted log message
ppapapetrou76 ddbf02a
address pr comments and add fix failing e2e tests
ppapapetrou76 d9251c9
Merge branch 'master' into issue-25378-oci-request-metrics
ppapapetrou76 5785394
address pr comments
ppapapetrou76 3589994
updates docs with the new metrics
ppapapetrou76 0a7224c
Merge branch 'master' into issue-25378-oci-request-metrics
ppapapetrou76 a19bc58
address final comment
ppapapetrou76 9ff85eb
Merge branch 'master' into issue-25378-oci-request-metrics
ppapapetrou76 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package metrics | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| log "github.com/sirupsen/logrus" | ||
|
|
||
| "github.com/argoproj/argo-cd/v3/util/oci" | ||
| ) | ||
|
|
||
| type OCIRequestType string | ||
|
|
||
| const ( | ||
| OCIRequestTypeExtract = "extract" | ||
| OCIRequestTypeResolveRevision = "resolve-revision" | ||
| OCIRequestTypeDigestMetadata = "digest-metadata" | ||
| OCIRequestTypeGetTags = "get-tags" | ||
| OCIRequestTypeTestRepo = "test-repo" | ||
| ) | ||
|
|
||
| // NewOCIClientEventHandlers creates event handlers to update OCI repo, related metrics | ||
| func NewOCIClientEventHandlers(metricsServer *MetricsServer) oci.EventHandlers { | ||
| return oci.EventHandlers{ | ||
| OnExtract: func(repo string) func() { | ||
| return processMetricFunc(metricsServer, repo, OCIRequestTypeExtract) | ||
| }, | ||
| OnResolveRevision: func(repo string) func() { | ||
| return processMetricFunc(metricsServer, repo, OCIRequestTypeResolveRevision) | ||
| }, | ||
| OnDigestMetadata: func(repo string) func() { | ||
| return processMetricFunc(metricsServer, repo, OCIRequestTypeDigestMetadata) | ||
| }, | ||
| OnGetTags: func(repo string) func() { | ||
| return processMetricFunc(metricsServer, repo, OCIRequestTypeGetTags) | ||
| }, | ||
| OnTestRepo: func(repo string) func() { | ||
| return processMetricFunc(metricsServer, repo, OCIRequestTypeTestRepo) | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func processMetricFunc(metricsServer *MetricsServer, repo string, requestType OCIRequestType) func() { | ||
| startTime := time.Now() | ||
| metricsServer.IncOCIRequest(repo, requestType) | ||
| log.Warnf("processing metric %s for repo %s", requestType, repo) | ||
| return func() { | ||
| metricsServer.ObserveOCIRequestDuration(repo, requestType, time.Since(startTime)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package metrics | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus/testutil" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestOCIClientEventHandlers(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| setup func() | ||
| teardown func() | ||
| testFunc func(t *testing.T) | ||
| }{ | ||
| { | ||
| name: "test event handlers", | ||
| testFunc: func(t *testing.T) { | ||
| t.Helper() | ||
| assert.NotPanics(t, func() { | ||
| metricsServer := NewMetricsServer() | ||
| eventHandlers := NewOCIClientEventHandlers(metricsServer) | ||
| eventHandlers.OnExtract("test") | ||
| eventHandlers.OnTestRepo("test") | ||
| eventHandlers.OnGetTags("test") | ||
| eventHandlers.OnResolveRevision("test") | ||
| eventHandlers.OnDigestMetadata("test") | ||
| c := metricsServer.ociRequestCounter | ||
| assert.Equal(t, 5, testutil.CollectAndCount(c)) | ||
| assert.InDelta(t, float64(1), testutil.ToFloat64(c.WithLabelValues("test", OCIRequestTypeExtract)), 0.01) | ||
| assert.InDelta(t, float64(1), testutil.ToFloat64(c.WithLabelValues("test", OCIRequestTypeResolveRevision)), 0.01) | ||
| assert.InDelta(t, float64(1), testutil.ToFloat64(c.WithLabelValues("test", OCIRequestTypeDigestMetadata)), 0.01) | ||
| assert.InDelta(t, float64(1), testutil.ToFloat64(c.WithLabelValues("test", OCIRequestTypeTestRepo)), 0.01) | ||
| assert.InDelta(t, float64(1), testutil.ToFloat64(c.WithLabelValues("test", OCIRequestTypeTestRepo)), 0.01) | ||
| }) | ||
| }, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| if tt.setup != nil { | ||
| tt.setup() | ||
| } | ||
| if tt.teardown != nil { | ||
| defer tt.teardown() | ||
| } | ||
| tt.testFunc(t) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.