-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Restore runner name label in listener metrics #4186
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
Open
air-hand
wants to merge
4
commits into
actions:master
Choose a base branch
from
air-hand:feat/restore-runner-name-label-in-listener-metrics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+132
−16
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f93b6dc
feat: restore `runner_name` label to listener metrics
air-hand 4480de7
feat: add runner_name metrics label in values.yaml as example
air-hand e0a0eb2
feat: add unit tests for job label generation methods
air-hand 7a18c00
feat: implement configurable label filtering with tests
air-hand 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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |||||
"testing" | ||||||
|
||||||
"github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1" | ||||||
"github.com/actions/actions-runner-controller/github/actions" | ||||||
"github.com/go-logr/logr" | ||||||
"github.com/prometheus/client_golang/prometheus" | ||||||
"github.com/stretchr/testify/assert" | ||||||
|
@@ -263,3 +264,113 @@ func TestExporterConfigDefaults(t *testing.T) { | |||||
|
||||||
assert.Equal(t, want, config) | ||||||
} | ||||||
|
||||||
func TestConfiguredLabelsOnly(t *testing.T) { | ||||||
allLabels := prometheus.Labels{ | ||||||
labelKeyRepository: "test-repo", | ||||||
labelKeyOrganization: "test-org", | ||||||
labelKeyJobName: "test-job", | ||||||
} | ||||||
|
||||||
configuredLabels := []string{labelKeyRepository, labelKeyJobName} | ||||||
|
||||||
got := configuredLabelsOnly(allLabels, configuredLabels) | ||||||
|
||||||
want := prometheus.Labels{ | ||||||
labelKeyRepository: "test-repo", | ||||||
labelKeyJobName: "test-job", | ||||||
} | ||||||
|
||||||
assert.Equal(t, want, got) | ||||||
assert.NotContains(t, got, labelKeyOrganization) | ||||||
} | ||||||
|
||||||
func TestCompletedJobAllLabels(t *testing.T) { | ||||||
config := ExporterConfig{ | ||||||
ScaleSetName: "test-scale-set", | ||||||
ScaleSetNamespace: "test-namespace", | ||||||
Enterprise: "", | ||||||
Organization: "org", | ||||||
Repository: "repo", | ||||||
ServerAddr: "", | ||||||
ServerEndpoint: "", | ||||||
Logger: logr.Discard(), | ||||||
Metrics: nil, // when metrics is nil, all default metrics should be registered | ||||||
} | ||||||
|
||||||
exporter, ok := NewExporter(config).(*exporter) | ||||||
require.True(t, ok, "expected exporter to be of type *exporter") | ||||||
require.NotNil(t, exporter) | ||||||
|
||||||
jobMessage := &actions.JobCompleted{ | ||||||
JobMessageBase: actions.JobMessageBase{ | ||||||
RepositoryName: "repo", | ||||||
OwnerName: "org", | ||||||
EventName: "", | ||||||
JobDisplayName: "test-job", | ||||||
JobWorkflowRef: "org/repo/.github/workflows/test.yml", | ||||||
}, | ||||||
Result: "success", | ||||||
RunnerId: 1, | ||||||
RunnerName: "runner1", | ||||||
} | ||||||
|
||||||
labels := exporter.completedJobLabels(jobMessage) | ||||||
|
||||||
want := prometheus.Labels{ | ||||||
labelKeyEnterprise: "", | ||||||
labelKeyRepository: "repo", | ||||||
labelKeyJobName: "test-job", | ||||||
labelKeyOrganization: "org", | ||||||
labelKeyEventName: "", | ||||||
labelKeyJobWorkflowRef: "org/repo/.github/workflows/test.yml", | ||||||
labelKeyJobResult: "success", | ||||||
labelKeyRunnerName: "runner1", | ||||||
} | ||||||
|
||||||
assert.Equal(t, want, labels) | ||||||
} | ||||||
|
||||||
func TestStartedJobAllLabels(t *testing.T) { | ||||||
config := ExporterConfig{ | ||||||
ScaleSetName: "test-scale-set", | ||||||
ScaleSetNamespace: "test-namespace", | ||||||
Enterprise: "", | ||||||
Organization: "org", | ||||||
Repository: "repo", | ||||||
ServerAddr: "", | ||||||
ServerEndpoint: "", | ||||||
Logger: logr.Discard(), | ||||||
Metrics: nil, // when metrics is nil, all default metrics should be registered | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test relies on implementation details by setting Metrics to nil and expecting specific behavior. Consider using a more explicit test setup that doesn't depend on nil handling.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
} | ||||||
|
||||||
exporter, ok := NewExporter(config).(*exporter) | ||||||
require.True(t, ok, "expected exporter to be of type *exporter") | ||||||
require.NotNil(t, exporter) | ||||||
|
||||||
jobMessage := &actions.JobStarted{ | ||||||
JobMessageBase: actions.JobMessageBase{ | ||||||
RepositoryName: "repo", | ||||||
OwnerName: "org", | ||||||
EventName: "", | ||||||
JobDisplayName: "test-job", | ||||||
JobWorkflowRef: "org/repo/.github/workflows/test.yml", | ||||||
}, | ||||||
RunnerId: 1, | ||||||
RunnerName: "runner1", | ||||||
} | ||||||
|
||||||
labels := exporter.startedJobLabels(jobMessage) | ||||||
|
||||||
want := prometheus.Labels{ | ||||||
labelKeyEnterprise: "", | ||||||
labelKeyRepository: "repo", | ||||||
labelKeyJobName: "test-job", | ||||||
labelKeyOrganization: "org", | ||||||
labelKeyEventName: "", | ||||||
labelKeyJobWorkflowRef: "org/repo/.github/workflows/test.yml", | ||||||
labelKeyRunnerName: "runner1", | ||||||
} | ||||||
|
||||||
assert.Equal(t, want, labels) | ||||||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test relies on implementation details by setting Metrics to nil and expecting specific behavior. Consider using a more explicit test setup that doesn't depend on nil handling.
Copilot uses AI. Check for mistakes.