diff --git a/rules/alerting.go b/rules/alerting.go index 34155a6dc..7fd5c68d7 100644 --- a/rules/alerting.go +++ b/rules/alerting.go @@ -16,7 +16,6 @@ package rules import ( "context" "fmt" - html_template "html/template" "net/url" "strings" "sync" @@ -35,7 +34,6 @@ import ( "github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/template" - "github.com/prometheus/prometheus/util/strutil" ) const ( @@ -44,8 +42,6 @@ const ( // AlertForStateMetricName is the metric name for 'for' state of alert. alertForStateMetricName = "ALERTS_FOR_STATE" - // AlertNameLabel is the label name indicating the name of an alert. - alertNameLabel = "alertname" // AlertStateLabel is the label name indicating the state of an alert. alertStateLabel = "alertstate" ) @@ -548,37 +544,3 @@ func (r *AlertingRule) String() string { return string(byt) } - -// HTMLSnippet returns an HTML snippet representing this alerting rule. The -// resulting snippet is expected to be presented in a
 element, so that
-// line breaks and other returned whitespace is respected.
-func (r *AlertingRule) HTMLSnippet(pathPrefix string) html_template.HTML {
-	alertMetric := model.Metric{
-		model.MetricNameLabel: alertMetricName,
-		alertNameLabel:        model.LabelValue(r.name),
-	}
-
-	labelsMap := make(map[string]string, len(r.labels))
-	for _, l := range r.labels {
-		labelsMap[l.Name] = html_template.HTMLEscapeString(l.Value)
-	}
-
-	annotationsMap := make(map[string]string, len(r.annotations))
-	for _, l := range r.annotations {
-		annotationsMap[l.Name] = html_template.HTMLEscapeString(l.Value)
-	}
-
-	ar := rulefmt.Rule{
-		Alert:       fmt.Sprintf("%s", pathPrefix+strutil.TableLinkForExpression(alertMetric.String()), r.name),
-		Expr:        fmt.Sprintf("%s", pathPrefix+strutil.TableLinkForExpression(r.vector.String()), html_template.HTMLEscapeString(r.vector.String())),
-		For:         model.Duration(r.holdDuration),
-		Labels:      labelsMap,
-		Annotations: annotationsMap,
-	}
-
-	byt, err := yaml.Marshal(ar)
-	if err != nil {
-		return html_template.HTML(fmt.Sprintf("error marshaling alerting rule: %q", html_template.HTMLEscapeString(err.Error())))
-	}
-	return html_template.HTML(byt)
-}
diff --git a/rules/alerting_test.go b/rules/alerting_test.go
index e5650a0cc..7e34a3ad1 100644
--- a/rules/alerting_test.go
+++ b/rules/alerting_test.go
@@ -15,7 +15,6 @@ package rules
 
 import (
 	"context"
-	"html/template"
 	"testing"
 	"time"
 
@@ -31,23 +30,6 @@ import (
 	"github.com/prometheus/prometheus/util/teststorage"
 )
 
-func TestAlertingRuleHTMLSnippet(t *testing.T) {
-	expr, err := parser.ParseExpr(`foo{html="BOLD"}`)
-	require.NoError(t, err)
-	rule := NewAlertingRule("testrule", expr, 0, labels.FromStrings("html", "BOLD"), labels.FromStrings("html", "BOLD"), nil, "", false, nil)
-
-	const want = template.HTML(`alert: testrule
-expr: foo{html="<b>BOLD<b>"}
-labels:
-  html: '<b>BOLD</b>'
-annotations:
-  html: '<b>BOLD</b>'
-`)
-
-	got := rule.HTMLSnippet("/test/prefix")
-	require.Equal(t, want, got, "incorrect HTML snippet; want:\n\n|%v|\n\ngot:\n\n|%v|", want, got)
-}
-
 func TestAlertingRuleState(t *testing.T) {
 	tests := []struct {
 		name   string
diff --git a/rules/manager.go b/rules/manager.go
index a9179bacf..f8e88b510 100644
--- a/rules/manager.go
+++ b/rules/manager.go
@@ -15,7 +15,6 @@ package rules
 
 import (
 	"context"
-	html_template "html/template"
 	"math"
 	"net/url"
 	"sort"
@@ -235,9 +234,6 @@ type Rule interface {
 	// GetEvaluationTimestamp returns last evaluation timestamp.
 	// NOTE: Used dynamically by rules.html template.
 	GetEvaluationTimestamp() time.Time
-	// HTMLSnippet returns a human-readable string representation of the rule,
-	// decorated with HTML elements for use the web frontend.
-	HTMLSnippet(pathPrefix string) html_template.HTML
 }
 
 // Group is a set of rules that have a logical relation.
diff --git a/rules/recording.go b/rules/recording.go
index 0681db9a2..2ce15979f 100644
--- a/rules/recording.go
+++ b/rules/recording.go
@@ -16,7 +16,6 @@ package rules
 import (
 	"context"
 	"fmt"
-	"html/template"
 	"net/url"
 	"sync"
 	"time"
@@ -27,7 +26,6 @@ import (
 	"github.com/prometheus/prometheus/model/rulefmt"
 	"github.com/prometheus/prometheus/promql"
 	"github.com/prometheus/prometheus/promql/parser"
-	"github.com/prometheus/prometheus/util/strutil"
 )
 
 // A RecordingRule records its vector expression into new timeseries.
@@ -179,25 +177,3 @@ func (rule *RecordingRule) GetEvaluationTimestamp() time.Time {
 	defer rule.mtx.Unlock()
 	return rule.evaluationTimestamp
 }
-
-// HTMLSnippet returns an HTML snippet representing this rule.
-func (rule *RecordingRule) HTMLSnippet(pathPrefix string) template.HTML {
-	ruleExpr := rule.vector.String()
-	labels := make(map[string]string, len(rule.labels))
-	for _, l := range rule.labels {
-		labels[l.Name] = template.HTMLEscapeString(l.Value)
-	}
-
-	r := rulefmt.Rule{
-		Record: fmt.Sprintf(`%s`, pathPrefix+strutil.TableLinkForExpression(rule.name), rule.name),
-		Expr:   fmt.Sprintf(`%s`, pathPrefix+strutil.TableLinkForExpression(ruleExpr), template.HTMLEscapeString(ruleExpr)),
-		Labels: labels,
-	}
-
-	byt, err := yaml.Marshal(r)
-	if err != nil {
-		return template.HTML(fmt.Sprintf("error marshaling recording rule: %q", template.HTMLEscapeString(err.Error())))
-	}
-
-	return template.HTML(byt)
-}
diff --git a/rules/recording_test.go b/rules/recording_test.go
index dd06b775f..366dac52a 100644
--- a/rules/recording_test.go
+++ b/rules/recording_test.go
@@ -15,7 +15,6 @@ package rules
 
 import (
 	"context"
-	"html/template"
 	"testing"
 	"time"
 
@@ -84,21 +83,6 @@ func TestRuleEval(t *testing.T) {
 	}
 }
 
-func TestRecordingRuleHTMLSnippet(t *testing.T) {
-	expr, err := parser.ParseExpr(`foo{html="BOLD"}`)
-	require.NoError(t, err)
-	rule := NewRecordingRule("testrule", expr, labels.FromStrings("html", "BOLD"))
-
-	const want = template.HTML(`record: testrule
-expr: foo{html="<b>BOLD<b>"}
-labels:
-  html: '<b>BOLD</b>'
-`)
-
-	got := rule.HTMLSnippet("/test/prefix")
-	require.Equal(t, want, got, "incorrect HTML snippet; want:\n\n%s\n\ngot:\n\n%s", want, got)
-}
-
 // TestRuleEvalDuplicate tests for duplicate labels in recorded metrics, see #5529.
 func TestRuleEvalDuplicate(t *testing.T) {
 	storage := teststorage.New(t)