Skip to content

Instantly share code, notes, and snippets.

@slok
Created October 23, 2025 06:17
Show Gist options
  • Select an option

  • Save slok/9408924d844049b675a8da9185422b40 to your computer and use it in GitHub Desktop.

Select an option

Save slok/9408924d844049b675a8da9185422b40 to your computer and use it in GitHub Desktop.
Example for the docs as an Sloth SLO plugin remote retrieval
package plugin
import (
"context"
"encoding/json"
"github.com/slok/sloth/pkg/common/conventions"
utilsdata "github.com/slok/sloth/pkg/common/utils/data"
pluginslov1 "github.com/slok/sloth/pkg/prometheus/plugin/slo/v1"
)
const (
PluginVersion = "prometheus/slo/v1"
PluginID = "sloth-examples/add_description_to_info/v1"
)
func NewPlugin(_ json.RawMessage, _ pluginslov1.AppUtils) (pluginslov1.Plugin, error) {
return plugin{}, nil
}
type plugin struct{}
func (p plugin) ProcessSLO(ctx context.Context, request *pluginslov1.Request, result *pluginslov1.Result) error {
// Search for info metric and add description label.
for i, r := range result.SLORules.MetadataRecRules.Rules {
if r.Record == conventions.PromMetaSLOInfoMetric {
r.Labels = utilsdata.MergeLabels(r.Labels, map[string]string{"description": request.SLO.Description})
result.SLORules.MetadataRecRules.Rules[i] = r
break
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment