Skip to content

Commit 88792b1

Browse files
committed
Moved warnings into apiclient
Signed-off-by: Joe Elliott <[email protected]>
1 parent bd85842 commit 88792b1

File tree

3 files changed

+50
-51
lines changed

3 files changed

+50
-51
lines changed

api/client.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import (
2525
"time"
2626
)
2727

28-
type Warnings []string
29-
3028
// DefaultRoundTripper is used if no RoundTripper is set in Config.
3129
var DefaultRoundTripper http.RoundTripper = &http.Transport{
3230
Proxy: http.ProxyFromEnvironment,

api/prometheus/v1/api.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,15 @@ type API interface {
230230
// Flags returns the flag values that Prometheus was launched with.
231231
Flags(ctx context.Context) (FlagsResult, error)
232232
// LabelNames returns all the unique label names present in the block in sorted order.
233-
LabelNames(ctx context.Context) ([]string, api.Warnings, error)
233+
LabelNames(ctx context.Context) ([]string, Warnings, error)
234234
// LabelValues performs a query for the values of the given label.
235-
LabelValues(ctx context.Context, label string) (model.LabelValues, api.Warnings, error)
235+
LabelValues(ctx context.Context, label string) (model.LabelValues, Warnings, error)
236236
// Query performs a query for the given time.
237-
Query(ctx context.Context, query string, ts time.Time) (model.Value, api.Warnings, error)
237+
Query(ctx context.Context, query string, ts time.Time) (model.Value, Warnings, error)
238238
// QueryRange performs a query for the given range.
239-
QueryRange(ctx context.Context, query string, r Range) (model.Value, api.Warnings, error)
239+
QueryRange(ctx context.Context, query string, r Range) (model.Value, Warnings, error)
240240
// Series finds series by label matchers.
241-
Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, api.Warnings, error)
241+
Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, Warnings, error)
242242
// Snapshot creates a snapshot of all current data into snapshots/<datetime>-<rand>
243243
// under the TSDB's data directory and returns the directory as response.
244244
Snapshot(ctx context.Context, skipHead bool) (SnapshotResult, error)
@@ -630,7 +630,7 @@ func (h *httpAPI) Flags(ctx context.Context) (FlagsResult, error) {
630630
return res, json.Unmarshal(body, &res)
631631
}
632632

633-
func (h *httpAPI) LabelNames(ctx context.Context) ([]string, api.Warnings, error) {
633+
func (h *httpAPI) LabelNames(ctx context.Context) ([]string, Warnings, error) {
634634
u := h.client.URL(epLabels, nil)
635635
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
636636
if err != nil {
@@ -644,7 +644,7 @@ func (h *httpAPI) LabelNames(ctx context.Context) ([]string, api.Warnings, error
644644
return labelNames, w, json.Unmarshal(body, &labelNames)
645645
}
646646

647-
func (h *httpAPI) LabelValues(ctx context.Context, label string) (model.LabelValues, api.Warnings, error) {
647+
func (h *httpAPI) LabelValues(ctx context.Context, label string) (model.LabelValues, Warnings, error) {
648648
u := h.client.URL(epLabelValues, map[string]string{"name": label})
649649
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
650650
if err != nil {
@@ -658,7 +658,7 @@ func (h *httpAPI) LabelValues(ctx context.Context, label string) (model.LabelVal
658658
return labelValues, w, json.Unmarshal(body, &labelValues)
659659
}
660660

661-
func (h *httpAPI) Query(ctx context.Context, query string, ts time.Time) (model.Value, api.Warnings, error) {
661+
func (h *httpAPI) Query(ctx context.Context, query string, ts time.Time) (model.Value, Warnings, error) {
662662
u := h.client.URL(epQuery, nil)
663663
q := u.Query()
664664

@@ -676,7 +676,7 @@ func (h *httpAPI) Query(ctx context.Context, query string, ts time.Time) (model.
676676
return model.Value(qres.v), warnings, json.Unmarshal(body, &qres)
677677
}
678678

679-
func (h *httpAPI) QueryRange(ctx context.Context, query string, r Range) (model.Value, api.Warnings, error) {
679+
func (h *httpAPI) QueryRange(ctx context.Context, query string, r Range) (model.Value, Warnings, error) {
680680
u := h.client.URL(epQueryRange, nil)
681681
q := u.Query()
682682

@@ -695,7 +695,7 @@ func (h *httpAPI) QueryRange(ctx context.Context, query string, r Range) (model.
695695
return model.Value(qres.v), warnings, json.Unmarshal(body, &qres)
696696
}
697697

698-
func (h *httpAPI) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, api.Warnings, error) {
698+
func (h *httpAPI) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, Warnings, error) {
699699
u := h.client.URL(epSeries, nil)
700700
q := u.Query()
701701

@@ -802,12 +802,15 @@ func (h *httpAPI) TargetsMetadata(ctx context.Context, matchTarget string, metri
802802
return res, json.Unmarshal(body, &res)
803803
}
804804

805+
// Warnings is an array of non critical errors
806+
type Warnings []string
807+
805808
// apiClient wraps a regular client and processes successful API responses.
806809
// Successful also includes responses that errored at the API level.
807810
type apiClient interface {
808811
URL(ep string, args map[string]string) *url.URL
809-
Do(context.Context, *http.Request) (*http.Response, []byte, api.Warnings, error)
810-
DoGetFallback(ctx context.Context, u *url.URL, args url.Values) (*http.Response, []byte, api.Warnings, error)
812+
Do(context.Context, *http.Request) (*http.Response, []byte, Warnings, error)
813+
DoGetFallback(ctx context.Context, u *url.URL, args url.Values) (*http.Response, []byte, Warnings, error)
811814
}
812815

813816
type apiClientImpl struct {
@@ -841,7 +844,7 @@ func (h *apiClientImpl) URL(ep string, args map[string]string) *url.URL {
841844
return h.client.URL(ep, args)
842845
}
843846

844-
func (h *apiClientImpl) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, api.Warnings, error) {
847+
func (h *apiClientImpl) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, Warnings, error) {
845848
resp, body, err := h.client.Do(ctx, req)
846849
if err != nil {
847850
return resp, body, nil, err
@@ -888,7 +891,7 @@ func (h *apiClientImpl) Do(ctx context.Context, req *http.Request) (*http.Respon
888891
}
889892

890893
// DoGetFallback will attempt to do the request as-is, and on a 405 it will fallback to a GET request.
891-
func (h *apiClientImpl) DoGetFallback(ctx context.Context, u *url.URL, args url.Values) (*http.Response, []byte, api.Warnings, error) {
894+
func (h *apiClientImpl) DoGetFallback(ctx context.Context, u *url.URL, args url.Values) (*http.Response, []byte, Warnings, error) {
892895
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(args.Encode()))
893896
if err != nil {
894897
return nil, nil, nil, err

api/prometheus/v1/api_test.go

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ import (
3030
json "github.com/json-iterator/go"
3131

3232
"github.com/prometheus/common/model"
33-
34-
"github.com/prometheus/client_golang/api"
3533
)
3634

3735
type apiTest struct {
38-
do func() (interface{}, api.Warnings, error)
36+
do func() (interface{}, Warnings, error)
3937
inWarnings []string
4038
inErr error
4139
inStatusCode int
@@ -45,7 +43,7 @@ type apiTest struct {
4543
reqParam url.Values
4644
reqMethod string
4745
res interface{}
48-
warnings api.Warnings
46+
warnings Warnings
4947
err error
5048
}
5149

@@ -66,7 +64,7 @@ func (c *apiTestClient) URL(ep string, args map[string]string) *url.URL {
6664
return u
6765
}
6866

69-
func (c *apiTestClient) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, api.Warnings, error) {
67+
func (c *apiTestClient) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, Warnings, error) {
7068

7169
test := c.curTest
7270

@@ -94,7 +92,7 @@ func (c *apiTestClient) Do(ctx context.Context, req *http.Request) (*http.Respon
9492
return resp, b, test.inWarnings, test.inErr
9593
}
9694

97-
func (c *apiTestClient) DoGetFallback(ctx context.Context, u *url.URL, args url.Values) (*http.Response, []byte, api.Warnings, error) {
95+
func (c *apiTestClient) DoGetFallback(ctx context.Context, u *url.URL, args url.Values) (*http.Response, []byte, Warnings, error) {
9896
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(args.Encode()))
9997
if err != nil {
10098
return nil, nil, nil, err
@@ -113,92 +111,92 @@ func TestAPIs(t *testing.T) {
113111
client: tc,
114112
}
115113

116-
doAlertManagers := func() func() (interface{}, api.Warnings, error) {
117-
return func() (interface{}, api.Warnings, error) {
114+
doAlertManagers := func() func() (interface{}, Warnings, error) {
115+
return func() (interface{}, Warnings, error) {
118116
v, err := promAPI.AlertManagers(context.Background())
119117
return v, nil, err
120118
}
121119
}
122120

123-
doCleanTombstones := func() func() (interface{}, api.Warnings, error) {
124-
return func() (interface{}, api.Warnings, error) {
121+
doCleanTombstones := func() func() (interface{}, Warnings, error) {
122+
return func() (interface{}, Warnings, error) {
125123
return nil, nil, promAPI.CleanTombstones(context.Background())
126124
}
127125
}
128126

129-
doConfig := func() func() (interface{}, api.Warnings, error) {
130-
return func() (interface{}, api.Warnings, error) {
127+
doConfig := func() func() (interface{}, Warnings, error) {
128+
return func() (interface{}, Warnings, error) {
131129
v, err := promAPI.Config(context.Background())
132130
return v, nil, err
133131
}
134132
}
135133

136-
doDeleteSeries := func(matcher string, startTime time.Time, endTime time.Time) func() (interface{}, api.Warnings, error) {
137-
return func() (interface{}, api.Warnings, error) {
134+
doDeleteSeries := func(matcher string, startTime time.Time, endTime time.Time) func() (interface{}, Warnings, error) {
135+
return func() (interface{}, Warnings, error) {
138136
return nil, nil, promAPI.DeleteSeries(context.Background(), []string{matcher}, startTime, endTime)
139137
}
140138
}
141139

142-
doFlags := func() func() (interface{}, api.Warnings, error) {
143-
return func() (interface{}, api.Warnings, error) {
140+
doFlags := func() func() (interface{}, Warnings, error) {
141+
return func() (interface{}, Warnings, error) {
144142
v, err := promAPI.Flags(context.Background())
145143
return v, nil, err
146144
}
147145
}
148146

149-
doLabelNames := func(label string) func() (interface{}, api.Warnings, error) {
150-
return func() (interface{}, api.Warnings, error) {
147+
doLabelNames := func(label string) func() (interface{}, Warnings, error) {
148+
return func() (interface{}, Warnings, error) {
151149
return promAPI.LabelNames(context.Background())
152150
}
153151
}
154152

155-
doLabelValues := func(label string) func() (interface{}, api.Warnings, error) {
156-
return func() (interface{}, api.Warnings, error) {
153+
doLabelValues := func(label string) func() (interface{}, Warnings, error) {
154+
return func() (interface{}, Warnings, error) {
157155
return promAPI.LabelValues(context.Background(), label)
158156
}
159157
}
160158

161-
doQuery := func(q string, ts time.Time) func() (interface{}, api.Warnings, error) {
162-
return func() (interface{}, api.Warnings, error) {
159+
doQuery := func(q string, ts time.Time) func() (interface{}, Warnings, error) {
160+
return func() (interface{}, Warnings, error) {
163161
return promAPI.Query(context.Background(), q, ts)
164162
}
165163
}
166164

167-
doQueryRange := func(q string, rng Range) func() (interface{}, api.Warnings, error) {
168-
return func() (interface{}, api.Warnings, error) {
165+
doQueryRange := func(q string, rng Range) func() (interface{}, Warnings, error) {
166+
return func() (interface{}, Warnings, error) {
169167
return promAPI.QueryRange(context.Background(), q, rng)
170168
}
171169
}
172170

173-
doSeries := func(matcher string, startTime time.Time, endTime time.Time) func() (interface{}, api.Warnings, error) {
174-
return func() (interface{}, api.Warnings, error) {
171+
doSeries := func(matcher string, startTime time.Time, endTime time.Time) func() (interface{}, Warnings, error) {
172+
return func() (interface{}, Warnings, error) {
175173
return promAPI.Series(context.Background(), []string{matcher}, startTime, endTime)
176174
}
177175
}
178176

179-
doSnapshot := func(skipHead bool) func() (interface{}, api.Warnings, error) {
180-
return func() (interface{}, api.Warnings, error) {
177+
doSnapshot := func(skipHead bool) func() (interface{}, Warnings, error) {
178+
return func() (interface{}, Warnings, error) {
181179
v, err := promAPI.Snapshot(context.Background(), skipHead)
182180
return v, nil, err
183181
}
184182
}
185183

186-
doRules := func() func() (interface{}, api.Warnings, error) {
187-
return func() (interface{}, api.Warnings, error) {
184+
doRules := func() func() (interface{}, Warnings, error) {
185+
return func() (interface{}, Warnings, error) {
188186
v, err := promAPI.Rules(context.Background())
189187
return v, nil, err
190188
}
191189
}
192190

193-
doTargets := func() func() (interface{}, api.Warnings, error) {
194-
return func() (interface{}, api.Warnings, error) {
191+
doTargets := func() func() (interface{}, Warnings, error) {
192+
return func() (interface{}, Warnings, error) {
195193
v, err := promAPI.Targets(context.Background())
196194
return v, nil, err
197195
}
198196
}
199197

200-
doTargetsMetadata := func(matchTarget string, metric string, limit string) func() (interface{}, api.Warnings, error) {
201-
return func() (interface{}, api.Warnings, error) {
198+
doTargetsMetadata := func(matchTarget string, metric string, limit string) func() (interface{}, Warnings, error) {
199+
return func() (interface{}, Warnings, error) {
202200
v, err := promAPI.TargetsMetadata(context.Background(), matchTarget, metric, limit)
203201
return v, nil, err
204202
}
@@ -911,7 +909,7 @@ type apiClientTest struct {
911909
response interface{}
912910
expectedBody string
913911
expectedErr *Error
914-
expectedWarnings api.Warnings
912+
expectedWarnings Warnings
915913
}
916914

917915
func (c *testClient) URL(ep string, args map[string]string) *url.URL {

0 commit comments

Comments
 (0)