@@ -2,25 +2,17 @@ package validation
2
2
3
3
import (
4
4
"fmt"
5
- "net/http"
6
5
"strings"
7
6
8
7
"github.com/prometheus/common/model"
9
- "github.com/weaveworks/common/httpgrpc"
10
8
11
9
"github.com/cortexproject/cortex/pkg/cortexpb"
12
10
)
13
11
14
- // ValidationError is an error returned by series validation. It provides a function to convert
15
- // the error into an HTTPGRPC error.
12
+ // ValidationError is an error returned by series validation.
16
13
//
17
14
// nolint:golint ignore stutter warning
18
- type ValidationError interface {
19
- error
20
-
21
- // ToHTTPGRPCError returns the httpgrpc version of the error.
22
- ToHTTPGRPCError () error
23
- }
15
+ type ValidationError error
24
16
25
17
// genericValidationError is a basic implementation of ValidationError which can be used when the
26
18
// error format only contains the cause and the series.
@@ -30,12 +22,8 @@ type genericValidationError struct {
30
22
series []cortexpb.LabelAdapter
31
23
}
32
24
33
- func (e * genericValidationError ) ToHTTPGRPCError () error {
34
- return httpgrpc .Errorf (http .StatusBadRequest , e .message , e .cause , formatLabelSet (e .series ))
35
- }
36
-
37
25
func (e * genericValidationError ) Error () string {
38
- return e . ToHTTPGRPCError (). Error ( )
26
+ return fmt . Sprintf ( e . message , e . cause , formatLabelSet ( e . series ) )
39
27
}
40
28
41
29
func newLabelNameTooLongError (series []cortexpb.LabelAdapter , labelName string ) ValidationError {
@@ -90,29 +78,20 @@ func newTooManyLabelsError(series []cortexpb.LabelAdapter, limit int) Validation
90
78
}
91
79
}
92
80
93
- func (e * tooManyLabelsError ) ToHTTPGRPCError () error {
94
- return httpgrpc .Errorf (
95
- http .StatusBadRequest ,
81
+ func (e * tooManyLabelsError ) Error () string {
82
+ return fmt .Sprintf (
96
83
"series has too many labels (actual: %d, limit: %d) series: '%s'" ,
97
84
len (e .series ), e .limit , cortexpb .FromLabelAdaptersToMetric (e .series ).String ())
98
85
}
99
86
100
- func (e * tooManyLabelsError ) Error () string {
101
- return e .ToHTTPGRPCError ().Error ()
102
- }
103
-
104
87
type noMetricNameError struct {}
105
88
106
89
func newNoMetricNameError () ValidationError {
107
90
return & noMetricNameError {}
108
91
}
109
92
110
- func (e * noMetricNameError ) ToHTTPGRPCError () error {
111
- return httpgrpc .Errorf (http .StatusBadRequest , "sample missing metric name" )
112
- }
113
-
114
93
func (e * noMetricNameError ) Error () string {
115
- return e . ToHTTPGRPCError (). Error ()
94
+ return "sample missing metric name"
116
95
}
117
96
118
97
type invalidMetricNameError struct {
@@ -125,12 +104,8 @@ func newInvalidMetricNameError(metricName string) ValidationError {
125
104
}
126
105
}
127
106
128
- func (e * invalidMetricNameError ) ToHTTPGRPCError () error {
129
- return httpgrpc .Errorf (http .StatusBadRequest , "sample invalid metric name: %.200q" , e .metricName )
130
- }
131
-
132
107
func (e * invalidMetricNameError ) Error () string {
133
- return e . ToHTTPGRPCError (). Error ( )
108
+ return fmt . Sprintf ( "sample invalid metric name: %.200q" , e . metricName )
134
109
}
135
110
136
111
// sampleValidationError is a ValidationError implementation suitable for sample validation errors.
@@ -140,12 +115,8 @@ type sampleValidationError struct {
140
115
timestamp int64
141
116
}
142
117
143
- func (e * sampleValidationError ) ToHTTPGRPCError () error {
144
- return httpgrpc .Errorf (http .StatusBadRequest , e .message , e .timestamp , e .metricName )
145
- }
146
-
147
118
func (e * sampleValidationError ) Error () string {
148
- return e . ToHTTPGRPCError (). Error ( )
119
+ return fmt . Sprintf ( e . message , e . timestamp , e . metricName )
149
120
}
150
121
151
122
func newSampleTimestampTooOldError (metricName string , timestamp int64 ) ValidationError {
0 commit comments