-
Notifications
You must be signed in to change notification settings - Fork 451
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
Fix Cronjob name #2717
Fix Cronjob name #2717
Changes from all commits
da49777
89a802f
32a18a2
f4c8f29
638511c
de54fd7
7b3f602
4b3f56e
b8386ee
f141eca
e1a796b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) | ||
component: auto-instrumentation | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: CronJob name propagated to the OTEL Service Name | ||
|
||
# One or more tracking issues related to the change | ||
issues: [2716] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | | ||
When instrumenting a `CronJob` it would generate a `Job` and then a `Pod`. | ||
Previously it would use the `Job` name as the Service name, generating too many different services on each cron execution. | ||
This release fixed to collect the `Job` parent's name, if it has one. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ import ( | |
"go.opentelemetry.io/otel/attribute" | ||
semconv "go.opentelemetry.io/otel/semconv/v1.7.0" | ||
appsv1 "k8s.io/api/apps/v1" | ||
batchv1 "k8s.io/api/batch/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
@@ -398,16 +399,19 @@ func chooseServiceName(pod corev1.Pod, resources map[string]string, index int) s | |
if name := resources[string(semconv.K8SDeploymentNameKey)]; name != "" { | ||
return name | ||
} | ||
if name := resources[string(semconv.K8SReplicaSetNameKey)]; name != "" { | ||
return name | ||
} | ||
if name := resources[string(semconv.K8SStatefulSetNameKey)]; name != "" { | ||
return name | ||
} | ||
if name := resources[string(semconv.K8SDaemonSetNameKey)]; name != "" { | ||
return name | ||
} | ||
if name := resources[string(semconv.K8SJobNameKey)]; name != "" { | ||
if name := resources[string(semconv.K8SCronJobNameKey)]; name != "" { | ||
return name | ||
} | ||
if name := resources[string(semconv.K8SCronJobNameKey)]; name != "" { | ||
if name := resources[string(semconv.K8SJobNameKey)]; name != "" { | ||
return name | ||
} | ||
if name := resources[string(semconv.K8SPodNameKey)]; name != "" { | ||
|
@@ -526,6 +530,26 @@ func (i *sdkInjector) addParentResourceLabels(ctx context.Context, uid bool, ns | |
if uid { | ||
resources[semconv.K8SJobUIDKey] = string(owner.UID) | ||
} | ||
|
||
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. Can we also add a unit test, while we're at it? LGTM otherwise. 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. sure, I'll take a look and get back to you soon. 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. done, pls give it another review :-) |
||
// parent of Job can be CronJob which we are interested to know | ||
j := batchv1.Job{} | ||
nsn := types.NamespacedName{Namespace: ns.Name, Name: owner.Name} | ||
backOff := wait.Backoff{Duration: 10 * time.Millisecond, Factor: 1.5, Jitter: 0.1, Steps: 20, Cap: 2 * time.Second} | ||
|
||
checkError := func(err error) bool { | ||
return apierrors.IsNotFound(err) | ||
} | ||
|
||
getJob := func() error { | ||
return i.client.Get(ctx, nsn, &j) | ||
} | ||
|
||
// use a retry loop to get the Job. A single call to client.get fails occasionally | ||
err := retry.OnError(backOff, checkError, getJob) | ||
if err != nil { | ||
i.logger.Error(err, "failed to get job", "job", nsn.Name, "namespace", nsn.Namespace) | ||
} | ||
i.addParentResourceLabels(ctx, uid, ns, j.ObjectMeta, resources) | ||
case "cronjob": | ||
resources[semconv.K8SCronJobNameKey] = owner.Name | ||
if uid { | ||
|
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.
I think it would be really nice to add an E2E test for this situation
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.
e2e done, pls give it another review :-)