From 5b555c637f4f6d3add30cd7b14158759aeee56e9 Mon Sep 17 00:00:00 2001 From: shubhangi-raj-meesho Date: Thu, 12 Feb 2026 15:34:23 +0530 Subject: [PATCH 1/2] Added isLoadTested and GrafanaLink fields in the the model Payload --- horizon/internal/predator/handler/model.go | 4 ++- horizon/internal/predator/handler/predator.go | 7 +++++ .../predator/handler/predator_helpers.go | 28 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/horizon/internal/predator/handler/model.go b/horizon/internal/predator/handler/model.go index c05cb329..eaacd518 100644 --- a/horizon/internal/predator/handler/model.go +++ b/horizon/internal/predator/handler/model.go @@ -11,6 +11,8 @@ type Payload struct { MetaData MetaData `json:"meta_data"` ConfigMapping ConfigMapping `json:"config_mapping"` DiscoveryConfigID uint `json:"discovery_config_id"` + IsLoadTested bool `json:"is_load_tested,omitempty"` + GrafanaLink string `json:"grafana_link,omitempty"` } type MetaData struct { @@ -44,7 +46,7 @@ type IOField struct { } type ConfigMapping struct { - ServiceDeployableID uint `json:"service_deployable_id"` + ServiceDeployableID uint `json:"service_deployable_id"` SourceModelName string `json:"source_model_name,omitempty"` } diff --git a/horizon/internal/predator/handler/predator.go b/horizon/internal/predator/handler/predator.go index a2459cdf..154f8356 100644 --- a/horizon/internal/predator/handler/predator.go +++ b/horizon/internal/predator/handler/predator.go @@ -172,6 +172,13 @@ func (p *Predator) HandleModelRequest(req ModelRequest, requestType string) (str if err := json.Unmarshal(payloadBytes, &payloadObject); err != nil { return constant.EmptyString, http.StatusInternalServerError, errors.New(errMsgProcessPayload) } + // Validate load test fields for promote requests + if requestType == PromoteRequestType && payloadObject.IsLoadTested { + if err := validateGrafanaLink(payloadObject.GrafanaLink); err != nil { + return constant.EmptyString, http.StatusBadRequest, err + } + } + derivedModelName, err := p.GetDerivedModelName(payloadObject, requestType) if err != nil { return constant.EmptyString, http.StatusInternalServerError, fmt.Errorf("failed to fetch derived model name: %w", err) diff --git a/horizon/internal/predator/handler/predator_helpers.go b/horizon/internal/predator/handler/predator_helpers.go index 91d53a03..7c9c23cf 100644 --- a/horizon/internal/predator/handler/predator_helpers.go +++ b/horizon/internal/predator/handler/predator_helpers.go @@ -2,6 +2,7 @@ package handler import ( "fmt" + "net/url" "path" "strings" @@ -106,3 +107,30 @@ func (p *Predator) isNonProductionEnvironment() bool { } return true } + +// validateGrafanaLink checks that the provided link is a valid HTTPS Grafana URL. +func validateGrafanaLink(link string) error { + if strings.TrimSpace(link) == "" { + return fmt.Errorf("grafana_link is required when is_load_tested is true") + } + + parsedURL, err := url.Parse(link) + if err != nil { + return fmt.Errorf("grafana_link is not a valid URL") + } + + if parsedURL.Scheme != "https" { + return fmt.Errorf("grafana_link must use https scheme") + } + + if parsedURL.Host == "" { + return fmt.Errorf("grafana_link must have a valid host") + } + + // Validate that the hostname contains "grafana" to ensure it's a Grafana link + if !strings.Contains(strings.ToLower(parsedURL.Hostname()), "grafana") { + return fmt.Errorf("grafana_link must point to a valid grafana host") + } + + return nil +} From b392c431ab89aeb6410e7f2200d469d74be1a7e0 Mon Sep 17 00:00:00 2001 From: shubhangi-raj-meesho Date: Thu, 19 Feb 2026 15:48:27 +0530 Subject: [PATCH 2/2] Resolved review comments, changed the field name and removed the grafana link validation function --- horizon/internal/predator/handler/model.go | 14 +++++----- horizon/internal/predator/handler/predator.go | 4 +-- .../predator/handler/predator_helpers.go | 28 ------------------- 3 files changed, 9 insertions(+), 37 deletions(-) diff --git a/horizon/internal/predator/handler/model.go b/horizon/internal/predator/handler/model.go index eaacd518..08b0e50c 100644 --- a/horizon/internal/predator/handler/model.go +++ b/horizon/internal/predator/handler/model.go @@ -6,13 +6,13 @@ import ( ) type Payload struct { - ModelName string `json:"model_name"` - ModelSource string `json:"model_source_path,omitempty"` - MetaData MetaData `json:"meta_data"` - ConfigMapping ConfigMapping `json:"config_mapping"` - DiscoveryConfigID uint `json:"discovery_config_id"` - IsLoadTested bool `json:"is_load_tested,omitempty"` - GrafanaLink string `json:"grafana_link,omitempty"` + ModelName string `json:"model_name"` + ModelSource string `json:"model_source_path,omitempty"` + MetaData MetaData `json:"meta_data"` + ConfigMapping ConfigMapping `json:"config_mapping"` + DiscoveryConfigID uint `json:"discovery_config_id"` + IsLoadTested bool `json:"is_load_tested,omitempty"` + LoadTestResultsLink string `json:"load_test_results_link,omitempty"` } type MetaData struct { diff --git a/horizon/internal/predator/handler/predator.go b/horizon/internal/predator/handler/predator.go index 154f8356..0a369ddb 100644 --- a/horizon/internal/predator/handler/predator.go +++ b/horizon/internal/predator/handler/predator.go @@ -174,8 +174,8 @@ func (p *Predator) HandleModelRequest(req ModelRequest, requestType string) (str } // Validate load test fields for promote requests if requestType == PromoteRequestType && payloadObject.IsLoadTested { - if err := validateGrafanaLink(payloadObject.GrafanaLink); err != nil { - return constant.EmptyString, http.StatusBadRequest, err + if payloadObject.LoadTestResultsLink == constant.EmptyString { + return constant.EmptyString, http.StatusBadRequest, errors.New("load test results link is required when load tested is true for the model requested") } } diff --git a/horizon/internal/predator/handler/predator_helpers.go b/horizon/internal/predator/handler/predator_helpers.go index 7c9c23cf..91d53a03 100644 --- a/horizon/internal/predator/handler/predator_helpers.go +++ b/horizon/internal/predator/handler/predator_helpers.go @@ -2,7 +2,6 @@ package handler import ( "fmt" - "net/url" "path" "strings" @@ -107,30 +106,3 @@ func (p *Predator) isNonProductionEnvironment() bool { } return true } - -// validateGrafanaLink checks that the provided link is a valid HTTPS Grafana URL. -func validateGrafanaLink(link string) error { - if strings.TrimSpace(link) == "" { - return fmt.Errorf("grafana_link is required when is_load_tested is true") - } - - parsedURL, err := url.Parse(link) - if err != nil { - return fmt.Errorf("grafana_link is not a valid URL") - } - - if parsedURL.Scheme != "https" { - return fmt.Errorf("grafana_link must use https scheme") - } - - if parsedURL.Host == "" { - return fmt.Errorf("grafana_link must have a valid host") - } - - // Validate that the hostname contains "grafana" to ensure it's a Grafana link - if !strings.Contains(strings.ToLower(parsedURL.Hostname()), "grafana") { - return fmt.Errorf("grafana_link must point to a valid grafana host") - } - - return nil -}