|
8 | 8 | "text/template" |
9 | 9 |
|
10 | 10 | "github.com/VictoriaMetrics/metricsql" |
11 | | - prommodel "github.com/prometheus/common/model" |
12 | 11 |
|
13 | 12 | "github.com/slok/sloth/pkg/common/validation" |
14 | 13 | pluginslov1 "github.com/slok/sloth/pkg/prometheus/plugin/slo/v1" |
@@ -39,51 +38,31 @@ func (p plugin) ProcessSLO(ctx context.Context, request *pluginslov1.Request, re |
39 | 38 | } |
40 | 39 |
|
41 | 40 | // VictoriaMetricsDialectValidator is the SLO flavour validator for victoria metrics backends dialect. |
42 | | -const VictoriaMetricsDialectValidator = victoriaMetricsDialectValidator(false) |
43 | | - |
44 | | -type victoriaMetricsDialectValidator bool |
45 | | - |
46 | | -func (victoriaMetricsDialectValidator) ValidateLabelKey(k string) error { |
47 | | - if k == prommodel.MetricNameLabel { |
48 | | - return fmt.Errorf("the label key %q is not allowed", prommodel.MetricNameLabel) |
49 | | - } |
50 | | - |
51 | | - if !prommodel.UTF8Validation.IsValidLabelName(k) { |
52 | | - return fmt.Errorf("the label key %q is not valid", k) |
53 | | - } |
54 | | - |
55 | | - return nil |
| 41 | +var VictoriaMetricsDialectValidator = victoriaMetricsDialectValidator{ |
| 42 | + promValidator: validation.PromQLDialectValidator, |
56 | 43 | } |
57 | 44 |
|
58 | | -func (victoriaMetricsDialectValidator) ValidateLabelValue(k string) error { |
59 | | - if k == "" { |
60 | | - return fmt.Errorf("the label value is required") |
61 | | - } |
62 | | - |
63 | | - if !prommodel.LabelValue(k).IsValid() { |
64 | | - return fmt.Errorf("the label value %q is not valid", k) |
65 | | - } |
66 | | - |
67 | | - return nil |
| 45 | +type victoriaMetricsDialectValidator struct { |
| 46 | + promValidator validation.SLODialectValidator |
68 | 47 | } |
69 | 48 |
|
70 | | -func (victoriaMetricsDialectValidator) ValidateAnnotationKey(k string) error { |
71 | | - if !prommodel.UTF8Validation.IsValidLabelName(k) { |
72 | | - return fmt.Errorf("the annotation key %q is not valid", k) |
73 | | - } |
| 49 | +var promExprTplAllowedFakeData = map[string]string{"window": "1m"} |
74 | 50 |
|
75 | | - return nil |
| 51 | +func (v victoriaMetricsDialectValidator) ValidateLabelKey(key string) error { |
| 52 | + return v.promValidator.ValidateLabelKey(key) |
76 | 53 | } |
77 | 54 |
|
78 | | -func (victoriaMetricsDialectValidator) ValidateAnnotationValue(k string) error { |
79 | | - if k == "" { |
80 | | - return fmt.Errorf("the annotation value is required") |
81 | | - } |
| 55 | +func (v victoriaMetricsDialectValidator) ValidateLabelValue(label string) error { |
| 56 | + return v.promValidator.ValidateLabelValue(label) |
| 57 | +} |
82 | 58 |
|
83 | | - return nil |
| 59 | +func (v victoriaMetricsDialectValidator) ValidateAnnotationKey(key string) error { |
| 60 | + return v.promValidator.ValidateAnnotationKey(key) |
84 | 61 | } |
85 | 62 |
|
86 | | -var promExprTplAllowedFakeData = map[string]string{"window": "1m"} |
| 63 | +func (v victoriaMetricsDialectValidator) ValidateAnnotationValue(annot string) error { |
| 64 | + return v.promValidator.ValidateAnnotationValue(annot) |
| 65 | +} |
87 | 66 |
|
88 | 67 | func (victoriaMetricsDialectValidator) ValidateQueryExpression(queryExpression string) error { |
89 | 68 | if queryExpression == "" { |
|
0 commit comments