From ebe649b8c312b99263e57f3f60549866b7405864 Mon Sep 17 00:00:00 2001 From: Bangseungjae Date: Mon, 14 Oct 2024 23:46:39 +0900 Subject: [PATCH] #828 Feature Prometheus API Signed-off-by: Bangseungjae --- api/models/metrics_config.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/api/models/metrics_config.go b/api/models/metrics_config.go index 41d5cb9b2..af18c66f5 100644 --- a/api/models/metrics_config.go +++ b/api/models/metrics_config.go @@ -8,8 +8,10 @@ package models import ( "context" + "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" + "github.com/go-openapi/validate" ) // MetricsConfig metrics config @@ -18,11 +20,30 @@ import ( type MetricsConfig struct { // value for prometheus enable or not - Prometheus bool `json:"prometheus,omitempty"` + // Required: true + Prometheus *bool `json:"prometheus"` } // Validate validates this metrics config func (m *MetricsConfig) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validatePrometheus(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *MetricsConfig) validatePrometheus(formats strfmt.Registry) error { + + if err := validate.Required("prometheus", "body", m.Prometheus); err != nil { + return err + } + return nil }