From dbd1233a79860a1f016314c776be9255a718805d Mon Sep 17 00:00:00 2001 From: Frank Jogeleit Date: Thu, 9 Nov 2023 09:06:14 +0100 Subject: [PATCH] message label in custom mode (#359) --- pkg/listener/metrics/model.go | 3 +++ pkg/listener/metrics/model_test.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/pkg/listener/metrics/model.go b/pkg/listener/metrics/model.go index b43782e7..0dcc8f75 100644 --- a/pkg/listener/metrics/model.go +++ b/pkg/listener/metrics/model.go @@ -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 { diff --git a/pkg/listener/metrics/model_test.go b/pkg/listener/metrics/model_test.go index ac84a1c5..f3d438c0 100644 --- a/pkg/listener/metrics/model_test.go +++ b/pkg/listener/metrics/model_test.go @@ -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) + } }