Skip to content

Commit

Permalink
message label in custom mode (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
fjogeleit authored Nov 9, 2023
1 parent 50a1a8a commit dbd1233
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/listener/metrics/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ var LabelGeneratorMapping = map[string]LabelCallback{
"status": func(m map[string]string, _ v1alpha2.ReportInterface, r v1alpha2.PolicyReportResult) {
m["status"] = string(r.Result)
},
"message": func(m map[string]string, _ v1alpha2.ReportInterface, r v1alpha2.PolicyReportResult) {
m["message"] = r.Message
},
}

func CreateLabelGenerator(labels []string, names []string) LabelGenerator {
Expand Down
4 changes: 4 additions & 0 deletions pkg/listener/metrics/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ func Test_LabelMappings(t *testing.T) {
if val, ok := results["kind"]; !ok && val != "" {
t.Errorf("expected empty name without resource, got: %s", val)
}
metrics.LabelGeneratorMapping["message"](results, preport, fixtures.FailPodResult)
if val, ok := results["namespace"]; !ok && val != fixtures.FailPodResult.Message {
t.Errorf("expected result for message label not found: %s", val)
}
}

0 comments on commit dbd1233

Please sign in to comment.