Skip to content
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

Related metrics tag name is wrong #7730

Closed
cugykw opened this issue Mar 1, 2024 · 3 comments · Fixed by #7731 or #7732
Closed

Related metrics tag name is wrong #7730

cugykw opened this issue Mar 1, 2024 · 3 comments · Fixed by #7731 or #7732
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@cugykw
Copy link
Contributor

cugykw commented Mar 1, 2024

When i used remote pipeline to replace the old reference pipeline approach,
I found that my grafana dashboard data was inaccurate,There are some pipeline metrics issues.

image

Expected Behavior

The task name in taskrun-related metrics is not empty, and the pipeline name
in pipelinerun-related metrics is not anonymous.

Actual Behavior

The relevant metrics tag names should be set correctly.

Steps to Reproduce the Problem

apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
  name: reproduce
spec:
  pipelineRef:
    resolver: git
    params:
    - name: url
      value: https://git.example.com/example/remote.yml
    - name: revision
      value: main
    - name: pathInRepo
      value: pipeline.yml
  1. Resources in the git repository:
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
  name: reproduce
spec:
  tasks:
  - name: f-1
    taskRef:
      resolver: git
      params:
      - name: url
        value: https://git.example.com/example/remote.yml
      - name: revision
        value: main
      - name: pathInRepo
        value: task.yml
apiVersion: tekton.dev/v1
kind: Task
metadata:
  name: reproduce
spec:
    steps:
    - image: centos7
      imagePullPolicy: Always
      name: demo
      script: |
        echo "hello"

Additional Info

tekton: 0.53.0

@cugykw cugykw added the kind/bug Categorizes issue or PR as related to a bug. label Mar 1, 2024
@cugykw
Copy link
Contributor Author

cugykw commented Mar 1, 2024

/assign

@cugykw cugykw changed the title The relevant metrics tag names should be set correctly Related metrics tag name is wrong Mar 1, 2024
@cugykw
Copy link
Contributor Author

cugykw commented Mar 1, 2024

In the above example, when pipelinerun and pipeline names are different, pipelineName label will display the name of pipelinerun, but context.pipeline.name will display the name of pipeline.

@cugykw
Copy link
Contributor Author

cugykw commented Mar 1, 2024

I noticed that propagatePipelineNameLabelToPipelineRun will initially set this label, and storePipelineSpecAndMergeMeta may set it here later. But storePipelineSpecAndMergeMeta will only be set once, and propagatePipelineNameLabelToPipelineRun will be reset back to the original value during the next reconcile.

func propagatePipelineNameLabelToPipelineRun(pr *v1.PipelineRun) error {
if pr.ObjectMeta.Labels == nil {
pr.ObjectMeta.Labels = make(map[string]string)
}
switch {
case pr.Spec.PipelineRef != nil && pr.Spec.PipelineRef.Name != "":
pr.ObjectMeta.Labels[pipeline.PipelineLabelKey] = pr.Spec.PipelineRef.Name
case pr.Spec.PipelineSpec != nil:
pr.ObjectMeta.Labels[pipeline.PipelineLabelKey] = pr.Name
case pr.Spec.PipelineRef != nil && pr.Spec.PipelineRef.Resolver != "":
pr.ObjectMeta.Labels[pipeline.PipelineLabelKey] = pr.Name
default:
return fmt.Errorf("pipelineRun %s not providing PipelineRef or PipelineSpec", pr.Name)
}
return nil
}

func storePipelineSpecAndMergeMeta(ctx context.Context, pr *v1.PipelineRun, ps *v1.PipelineSpec, meta *resolutionutil.ResolvedObjectMeta) error {
// Only store the PipelineSpec once, if it has never been set before.
if pr.Status.PipelineSpec == nil {
pr.Status.PipelineSpec = ps
if meta == nil {
return nil
}
// Propagate labels from Pipeline to PipelineRun. PipelineRun labels take precedences over Pipeline.
pr.ObjectMeta.Labels = kmap.Union(meta.Labels, pr.ObjectMeta.Labels)
pr.ObjectMeta.Labels[pipeline.PipelineLabelKey] = meta.Name
// Propagate annotations from Pipeline to PipelineRun. PipelineRun annotations take precedences over Pipeline.
pr.ObjectMeta.Annotations = kmap.Union(kmap.ExcludeKeys(meta.Annotations, tknreconciler.KubectlLastAppliedAnnotationKey), pr.ObjectMeta.Annotations)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
1 participant