feat: add error metrics for PipelineRun and TaskRun signing failures#1325
Conversation
|
Hi @mathur07. Thanks for your PR. I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
aThorp96
left a comment
There was a problem hiding this comment.
LGTM! One optional suggestion. Approval pending go fmt
|
@mathur07 can you go thought easycla process, ? Would you also Remove the WIP on your PR description |
| if (signableType.Type() == "TaskRunArtifact" || signableType.Type() == "PipelineRunArtifact") && o.Recorder != nil { | ||
| o.Recorder.RecordErrorMetric(ctx, "storage") | ||
| } |
There was a problem hiding this comment.
The signableType.Type() == "..." logic appears a lot. Could this be abstracted? E.g.:
if err := b.StorePayload(ctx, tektonObj, rawPayload, string(signature), storageOpts); err != nil {
logger.Error(err)
o.recordErrorMetrics(ctx, signableType.Type(), "storage")
}
// ...
func (o *ObjectSigner) recordErrorMetric(ctx context.Context, signableType string, errType string) {
recordableTypes := []string{"TaskRunArtifact", "PipelineRunArtifact"}
if o.Recorder != nil && slices.Contains(recordableTypes, signableType) {
o.Recorder.RecordErrorMetric(ctx, errType)
}
}There was a problem hiding this comment.
i have abstracted it:
func (o *ObjectSigner) shouldRecordError(kind string) bool { return kind == "TaskRunArtifact" || kind == "PipelineRunArtifact" }
There was a problem hiding this comment.
Let me know if it looks good. TY!
There was a problem hiding this comment.
Thanks @mathur07! It's a bit better, however there is still a fair bit of duplication. Any objection to consolidating the shouldRecordErrorMetric and o.Recorder != nil into the same function like in my example?
There was a problem hiding this comment.
+1
Use constant for TaskRunArtifact and PipelineRunArtifact kinds
5b6f340 to
475aef3
Compare
|
@khrm can you PTAL too. TY! |
|
@aThorp96: changing LGTM is restricted to collaborators DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
@anithapriyanatarajan can you PTAL TY! |
| // New error metric for PipelineRun signing failures, defined as a Float64 measure. | ||
| pipelineRunErrorCount = stats.Float64( | ||
| chains.PipelineRunErrorCountName, | ||
| chains.PipelineRunErrorCountDesc, | ||
| stats.UnitDimensionless, | ||
| ) | ||
|
|
||
| // Define a view for the PipelineRun error metric with an error_type tag. | ||
| pipelineErrorView *view.View | ||
|
|
||
| // Tag key for error type. | ||
| errorTypeKey, _ = tag.NewKey("error_type") |
There was a problem hiding this comment.
I meant to include these comments in my previous request to remove superfluous comments. Do you mind removing these comments?
| if err != nil { | ||
| logger.Error(err) | ||
| if o.shouldRecordError(signableType.Type()) && o.Recorder != nil { | ||
| o.Recorder.RecordErrorMetric(ctx, "payload_creation") |
| logger.Warnf("Unable to marshal payload: %v", signerType, obj) | ||
| logger.Warnf("Unable to marshal payload for %s: %v", signerType, err) | ||
| if o.shouldRecordError(signableType.Type()) && o.Recorder != nil { | ||
| o.Recorder.RecordErrorMetric(ctx, "marshal_payload") |
There was a problem hiding this comment.
same here error types better use constant
There was a problem hiding this comment.
E.g.:
type TaskRunErrorMetric string
const (
TaskRunMarshalPayloadError TaskRunErrorMetric = "marshal_payload"
TaskRunPayloadCreationError = "payload_creation"
...
)
func RecordErrorMetric(ctx context.Context, errType TaskRunErrorMetric) { ... }There was a problem hiding this comment.
ack.
made requested changes PTAL
This commit adds new error metrics to track signing failures for both PipelineRun and TaskRun artifacts. - Error recording in the signing logic with error_type tags. - Updated metrics and tests in both pipelinerunmetrics and taskrunmetrics.
aThorp96
left a comment
There was a problem hiding this comment.
Some context around the changes included in my refactor
There was a problem hiding this comment.
This file seemed to define constants not for chains, but for metrics. Since there are metrics-specific modules, it didn't make sense to me to define them here. It also is an antipattern in my experience to define modules and files to group things by type (like constants) rather than domain (like metrics). The contents of this file have been split between three files based on domain: pkg/pipelinerunmetrics/metrics.go, pkg/taskrunmetrics/metrics.go, and a new file pkg/metrics/common.go.
| type MetricsRecorder interface { | ||
| RecordCountMetrics(ctx context.Context, MetricType string) | ||
| } |
There was a problem hiding this comment.
This interface should is implemented by pipelinerunmetrics.Recorder and taskrunmetricsRecorder. So it's been moved to pkg/metrics/common.go, and the implementations can now enforce at the type level that they do implement the interface without a circular import...
|
|
||
| // Recorder is an interface for any object which may record metrics | ||
| type Recorder interface { | ||
| RecordCountMetrics(ctx context.Context, MetricType Metric) |
There was a problem hiding this comment.
Note that RecordCountMetrics changed its MetricType parameter from string to Metric
| pipelineRunSignedName common.Metric = "pipelinerun_sign_created_total" | ||
| pipelineRunSignedDesc string = "Total number of signed messages for pipelineruns" | ||
| pipelineRunUploadedName common.Metric = "pipelinerun_payload_uploaded_total" | ||
| pipelineRunUploadedDesc string = "Total number of uploaded payloads for pipelineruns" | ||
| pipelineRunStoredName common.Metric = "pipelinerun_payload_stored_total" | ||
| pipelineRunStoredDesc string = "Total number of stored payloads for pipelineruns" | ||
| pipelineRunMarkedName common.Metric = "pipelinerun_marked_signed_total" | ||
| pipelineRunMarkedDesc string = "Total number of objects marked as signed for pipelineruns" | ||
| pipelineRunErrorCountName common.Metric = "pipelinerun_signing_failures_total" | ||
| pipelineRunErrorCountDesc string = "Total number of PipelineRun signing failures" |
There was a problem hiding this comment.
Since these are no longer in the chains package (they were only referenced in the pipelinerunmetrics package), they no longer need to be public, so the API is cleaned up a bit
| ) | ||
|
|
||
| // Recorder holds keys for Tekton metrics | ||
| var _ common.Recorder = &Recorder{} |
There was a problem hiding this comment.
See my above comment regarding the interface implementation enforcement
|
@jkhelil can you please take a look at the new changes? TY! |
| ) | ||
|
|
||
| // shouldRecordError returns true if the artifact type is TaskRunArtifact or PipelineRunArtifact. | ||
| func (o *ObjectSigner) shouldRecordError(kind string) bool { |
There was a problem hiding this comment.
I'm a bit confused with the name of function name and the logic inside the function
|
/approve |
|
/lgtm |
|
@aThorp96: changing LGTM is restricted to collaborators DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
/cc @lcarva do you mind reviewing this PR, if you have a chance? |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aThorp96, lcarva, PuneetPunamiya The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/lgtm |
|
The following is the coverage report on the affected files.
|
|
/ok-to-test |
|
The following is the coverage report on the affected files.
|
This commit adds new error metrics to track signing failures for both PipelineRun and TaskRun artifacts.
Part-resolution: Jira Issue & #984
Changes
Submitter Checklist
As the author of this PR, please check off the items in this checklist:
functionality, content, code)
Release Notes