From 645eef4ad57bfaa0e50b9d8e2c98f198186188ab Mon Sep 17 00:00:00 2001
From: Xabier Larrakoetxea <me@slok.dev>
Date: Fri, 11 Apr 2025 07:37:49 +0200
Subject: [PATCH] Add the original SLO group source information to the plugin
 request

Signed-off-by: Xabier Larrakoetxea <me@slok.dev>
---
 internal/app/generate/generate.go  | 5 +++--
 internal/app/generate/process.go   | 2 ++
 pkg/prometheus/plugin/slo/v1/v1.go | 4 ++++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/internal/app/generate/generate.go b/internal/app/generate/generate.go
index 273d1a4..e9dff27 100644
--- a/internal/app/generate/generate.go
+++ b/internal/app/generate/generate.go
@@ -175,7 +175,7 @@ func (s Service) Generate(ctx context.Context, r Request) (*Response, error) {
 		slo.Labels = utilsdata.MergeLabels(slo.Labels, r.ExtraLabels)
 
 		// Generate SLO result.
-		result, err := s.generateSLO(ctx, r.Info, slo)
+		result, err := s.generateSLO(ctx, r.Info, r.SLOGroup, slo)
 		if err != nil {
 			return nil, fmt.Errorf("could not generate %q slo: %w", slo.ID, err)
 		}
@@ -188,7 +188,7 @@ func (s Service) Generate(ctx context.Context, r Request) (*Response, error) {
 	}, nil
 }
 
-func (s Service) generateSLO(ctx context.Context, info model.Info, slo model.PromSLO) (*model.PromSLORules, error) {
+func (s Service) generateSLO(ctx context.Context, info model.Info, sloGroup model.PromSLOGroup, slo model.PromSLO) (*model.PromSLORules, error) {
 	logger := s.logger.WithCtxValues(ctx).WithValues(log.Kv{"slo": slo.ID})
 
 	// Generate the MWMB alerts.
@@ -242,6 +242,7 @@ func (s Service) generateSLO(ctx context.Context, info model.Info, slo model.Pro
 		Info:           info,
 		MWMBAlertGroup: *as,
 		SLO:            slo,
+		SLOGroup:       sloGroup,
 	}
 	res := &SLOProcessorResult{}
 	for _, p := range sloProcessors {
diff --git a/internal/app/generate/process.go b/internal/app/generate/process.go
index 0dba86e..33de3e7 100644
--- a/internal/app/generate/process.go
+++ b/internal/app/generate/process.go
@@ -13,6 +13,7 @@ import (
 type SLOProcessorRequest struct {
 	Info           model.Info
 	SLO            model.PromSLO
+	SLOGroup       model.PromSLOGroup
 	MWMBAlertGroup model.MWMBAlertGroup
 }
 type SLOProcessorResult struct {
@@ -51,6 +52,7 @@ func NewSLOProcessorFromSLOPluginV1(pluginFactory pluginslov1.PluginFactory, log
 			Info:           req.Info,
 			SLO:            req.SLO,
 			MWMBAlertGroup: req.MWMBAlertGroup,
+			OriginalSource: req.SLOGroup.OriginalSource,
 		}
 		rs := &pluginslov1.Result{
 			SLORules: res.SLORules,
diff --git a/pkg/prometheus/plugin/slo/v1/v1.go b/pkg/prometheus/plugin/slo/v1/v1.go
index 2881f81..9d1118a 100644
--- a/pkg/prometheus/plugin/slo/v1/v1.go
+++ b/pkg/prometheus/plugin/slo/v1/v1.go
@@ -29,6 +29,10 @@ type AppUtils struct {
 type Request struct {
 	// Info about the application and execution, normally used as metadata.
 	Info model.Info
+	// OriginalSource is the original specification of the SLO came from, this is informative data that
+	// can be used to make decision on plugins, it should be used only as RO.
+	// The information used on the generation is the SLO model itself not this one.
+	OriginalSource model.PromSLOGroupSource
 	// The SLO to process and generate the final Prom rules.
 	SLO model.PromSLO
 	// The SLO MWMBAlertGroup selected.
-- 
GitLab