forked from awslabs/amazon-timestream-connector-prometheus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
248 lines (208 loc) · 8.38 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
the License. A copy of the License is located at
http://www.apache.org/licenses/LICENSE-2.0
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
and limitations under the License.
*/
// This file contains all the error messages and their HTTP status code the Prometheus Connector may return.
package errors
import (
"fmt"
"net/http"
"github.com/prometheus/prometheus/prompb"
)
type baseConnectorError struct {
statusCode int
errorMsg string
message string
}
func (e *baseConnectorError) StatusCode() int {
return e.statusCode
}
func (e *baseConnectorError) Error() string {
return e.errorMsg
}
func (e *baseConnectorError) Message() string {
return e.message
}
type MissingDestinationError struct {
baseConnectorError
}
func NewMissingDestinationError() error {
base := baseConnectorError{
statusCode: http.StatusBadRequest,
errorMsg: "no default database or default table has been set",
message: "The environment variables default-database and default-table must be specified in the Lambda function." +
labelErrorMessage,
}
return &MissingDestinationError{baseConnectorError: base}
}
type ParseEnableLoggingError struct {
baseConnectorError
}
func NewParseEnableLoggingError(enableLogging string) error {
return &ParseEnableLoggingError{baseConnectorError: baseConnectorError{
statusCode: http.StatusBadRequest,
errorMsg: fmt.Sprintf("error occurred while parsing enable-logging, expected true or false, but received '%s'", enableLogging),
message: "The value specified in the enable-logging option is not one of the accepted values. " +
acceptedValueErrorMessage,
}}
}
type ParseMetricLabelError struct {
baseConnectorError
}
func NewParseMetricLabelError(failOnLongMetricLabelName string) error {
return &ParseMetricLabelError{baseConnectorError: baseConnectorError{
statusCode: http.StatusBadRequest,
errorMsg: fmt.Sprintf("error occurred while parsing fail-on-long-label, expected true or false, but received '%s'", failOnLongMetricLabelName),
message: "The value specified in the fail-on-long-label option is not one of the accepted values. " +
acceptedValueErrorMessage,
}}
}
type ParseSampleOptionError struct {
baseConnectorError
}
func NewParseSampleOptionError(failOnInvalidSample string) error {
return &ParseSampleOptionError{baseConnectorError: baseConnectorError{
statusCode: http.StatusBadRequest,
errorMsg: fmt.Sprintf("error occurred while parsing fail-on-invalid-sample, expected true or false, but received '%s'", failOnInvalidSample),
message: "The value specified in the fail-on-invalid-sample option is not one of the accepted values. " +
acceptedValueErrorMessage,
}}
}
type ParseRetriesError struct {
baseConnectorError
}
func NewParseRetriesError(retries string, operation string) error {
return &ParseRetriesError{
baseConnectorError: baseConnectorError{
statusCode: http.StatusBadRequest,
errorMsg: fmt.Sprintf(
"error occurred while parsing max-%s-retries, expected an integer, but received '%s'",
operation, retries,
),
message: fmt.Sprintf(
"The value specified in the max-%s-retries option is not one of the accepted values. %s",
operation, acceptedValueErrorMessage,
),
},
}
}
type ParseBasicAuthHeaderError struct {
baseConnectorError
}
func NewParseBasicAuthHeaderError() error {
base := baseConnectorError{
statusCode: http.StatusBadRequest,
errorMsg: "expected a valid AWS credentials, please check Prometheus configuration for basic auth",
message: "The request must contain a valid basic authentication header, please refer to the documentation on how to configure Prometheus.",
}
return &ParseBasicAuthHeaderError{baseConnectorError: base}
}
type MissingHeaderError struct {
baseConnectorError
}
func NewMissingHeaderError(readHeader, writeHeader string) error {
return &MissingHeaderError{baseConnectorError: baseConnectorError{
statusCode: http.StatusBadRequest,
errorMsg: fmt.Sprintf("No appropriate header found in the request. Please ensure the request header contains either %s or %s.", readHeader, writeHeader),
message: fmt.Sprintf("The request must contain either %s or %s in the header.", readHeader, writeHeader),
}}
}
type MissingDatabaseWithWriteError struct {
baseConnectorError
}
func NewMissingDatabaseWithWriteError(defaultDatabase string, timeSeries *prompb.TimeSeries) error {
base := baseConnectorError{
statusCode: http.StatusBadRequest,
errorMsg: fmt.Sprintf("the given database name: %s cannot be found for the current time series %v", defaultDatabase, timeSeries),
message: "The environment variables default-database must be configured for the Prometheus Connector. " +
labelErrorMessage,
}
return &MissingDatabaseWithWriteError{baseConnectorError: base}
}
type MissingTableWithWriteError struct {
baseConnectorError
}
func NewMissingTableWithWriteError(defaultTable string, timeSeries *prompb.TimeSeries) error {
base := baseConnectorError{
statusCode: http.StatusBadRequest,
errorMsg: fmt.Sprintf("the given table name: %s cannot be found for the current time series %v", defaultTable, timeSeries),
message: "The environment variables default-table must be configured for the Prometheus Connector. " +
labelErrorMessage,
}
return &MissingTableWithWriteError{baseConnectorError: base}
}
type MissingDatabaseError struct {
baseConnectorError
}
func NewMissingDatabaseError(defaultDatabase string) error {
base := baseConnectorError{
statusCode: http.StatusBadRequest,
errorMsg: fmt.Sprintf("the given table name: %s cannot be found. Please provide the table name with the flag default-database.", defaultDatabase),
message: "The environment variable default-database must be specified for the Prometheus Connector." +
labelErrorMessage,
}
return &MissingDatabaseError{baseConnectorError: base}
}
type MissingTableError struct {
baseConnectorError
}
func NewMissingTableError(defaultTable string) error {
base := baseConnectorError{
statusCode: http.StatusBadRequest,
errorMsg: fmt.Sprintf("the given table name: %s cannot be found. Please provide the table name with the flag default-table.", defaultTable),
message: "The environment variable default-table must be specified for the Prometheus Connector." +
labelErrorMessage,
}
return &MissingTableError{baseConnectorError: base}
}
type UnknownMatcherError struct {
baseConnectorError
}
func NewUnknownMatcherError() error {
base := baseConnectorError{
statusCode: http.StatusBadRequest,
errorMsg: "unknown matcher in query, Prometheus only supports 4 types of matchers in the filter: =, !=, =~, !~",
message: "Prometheus only supports 4 types of matchers in the filter: =, !=, =~, !~, others matchers will be invalid. ",
}
return &UnknownMatcherError{baseConnectorError: base}
}
type LongLabelNameError struct {
baseConnectorError
}
func NewLongLabelNameError(measureValueName string, maxMeasureNameLength int) error {
base := baseConnectorError{
statusCode: http.StatusBadRequest,
errorMsg: fmt.Sprintf("metric name '%s' exceeds %d characters, the maximum length supported by Timestream", measureValueName, maxMeasureNameLength),
message: "The metric name exceeds the maximum Timestream supported length, and the `fail-on-long-label` is set to `true`. " +
detailsErrorMessage,
}
return &LongLabelNameError{baseConnectorError: base}
}
type InvalidSampleValueError struct {
baseConnectorError
}
func NewInvalidSampleValueError(timeSeriesValue float64) error {
base := baseConnectorError{
statusCode: http.StatusBadRequest,
errorMsg: fmt.Sprintf("invalid sample value: %f", timeSeriesValue),
message: "Timestream only accepts finite IEEE Standard 754 floating-point precision. " +
"Non-finite sample value will fail the program with fail-on-invalid-sample-value enabled.",
}
return &InvalidSampleValueError{baseConnectorError: base}
}
type SDKNonRequestError struct {
baseConnectorError
}
func NewSDKNonRequestError(err error) error {
base := baseConnectorError{
statusCode: http.StatusBadRequest,
errorMsg: err.Error(),
message: err.Error(),
}
return &SDKNonRequestError{baseConnectorError: base}
}