diff --git a/Dockerfile b/Dockerfile index 312700bc..8fb00dfb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # Dockerfile has specific requirement to put this ARG at the beginning: # https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact -ARG BUILDER_IMAGE=golang:1.23 +ARG BUILDER_IMAGE=golang:1.24 ARG BASE_IMAGE=gcr.io/distroless/static:nonroot ## Multistage build diff --git a/cmd/epp/main.go b/cmd/epp/main.go index fa63f0bc..39baf18b 100644 --- a/cmd/epp/main.go +++ b/cmd/epp/main.go @@ -163,6 +163,7 @@ func run() error { setupLog.Error(err, "Failed to create metric mapping from flags.") return err } + verifyMetricMapping(*mapping, setupLog) pmf := backendmetrics.NewPodMetricsFactory(&backendmetrics.PodMetricsClientImpl{MetricMapping: mapping}, *refreshMetricsInterval) // Setup runner. @@ -304,3 +305,16 @@ func validateFlags() error { return nil } + +func verifyMetricMapping(mapping backendmetrics.MetricMapping, logger logr.Logger) { + if mapping.TotalQueuedRequests == nil { + logger.Info("Not scraping metric: TotalQueuedRequests") + } + if mapping.KVCacheUtilization == nil { + logger.Info("Not scraping metric: KVCacheUtilization") + } + if mapping.LoraRequestInfo == nil { + logger.Info("Not scraping metric: LoraRequestInfo") + } + +} diff --git a/pkg/epp/backend/metrics/metrics_spec.go b/pkg/epp/backend/metrics/metrics_spec.go index ce0c075d..f6f904a9 100644 --- a/pkg/epp/backend/metrics/metrics_spec.go +++ b/pkg/epp/backend/metrics/metrics_spec.go @@ -41,6 +41,9 @@ type MetricMapping struct { // "metric_name{label1=value1}" // "metric_name{label1=value1,label2=value2}" func stringToMetricSpec(specStr string) (*MetricSpec, error) { + if specStr == "" { + return nil, nil // Allow empty strings to represent nil MetricSpecs + } specStr = strings.TrimSpace(specStr) metricName := specStr labels := make(map[string]string) diff --git a/pkg/epp/backend/metrics/metrics_spec_test.go b/pkg/epp/backend/metrics/metrics_spec_test.go index 82804206..e62bc5ff 100644 --- a/pkg/epp/backend/metrics/metrics_spec_test.go +++ b/pkg/epp/backend/metrics/metrics_spec_test.go @@ -32,7 +32,7 @@ func TestStringToMetricSpec(t *testing.T) { name: "empty string", input: "", want: nil, - wantErr: true, + wantErr: false, }, { name: "no labels", @@ -152,14 +152,9 @@ func TestStringToMetricSpec(t *testing.T) { t.Errorf("stringToMetricSpec() error = %v, wantErr %v", err, tt.wantErr) return } - if tt.wantErr { - if got != nil { // handles if we got a nil spec and didn't expect an error - t.Errorf("stringToMetricSpec() = %v, want %v", got, tt.want) - return - } - } else { - if got == nil { - t.Fatalf("stringToMetricSpec() = got nil but wanted %v", tt.want) + if tt.want != nil && got != nil { // compare maps directly + if tt.want.Labels == nil { + tt.want.Labels = make(map[string]string) } if !reflect.DeepEqual(got.MetricName, tt.want.MetricName) { t.Errorf("stringToMetricSpec() got MetricName = %v, want %v", got.MetricName, tt.want.MetricName) @@ -167,6 +162,8 @@ func TestStringToMetricSpec(t *testing.T) { if !reflect.DeepEqual(got.Labels, tt.want.Labels) { t.Errorf("stringToMetricSpec() got Labels = %v, want %v", got.Labels, tt.want.Labels) } + } else if tt.want != got { // handles if one is nil and the other isn't + t.Errorf("stringToMetricSpec() = %v, want %v", got, tt.want) } }) }