Skip to content

Commit

Permalink
Merge pull request #1013 from cloudflare/errText
Browse files Browse the repository at this point in the history
Add fallback error text
  • Loading branch information
prymitive authored Jun 24, 2024
2 parents 66614e1 + 0090686 commit e9d8514
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/promapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func streamConfig(r io.Reader) (cfg PrometheusConfig, err error) {
defer dummyReadAll(r)

var yamlBody, status, errType, errText string
errText = "empty response object"
decoder := current.Object(
current.Key("status", current.Value(func(s string, _ bool) {
status = s
Expand Down
1 change: 1 addition & 0 deletions internal/promapi/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func streamFlags(r io.Reader) (flags v1.FlagsResult, err error) {
defer dummyReadAll(r)

var status, errType, errText string
errText = "empty response object"
flags = v1.FlagsResult{}
decoder := current.Object(
current.Key("status", current.Value(func(s string, _ bool) {
Expand Down
1 change: 1 addition & 0 deletions internal/promapi/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func streamMetadata(r io.Reader) (meta map[string][]v1.Metadata, err error) {
defer dummyReadAll(r)

var status, errType, errText string
errText = "empty response object"
meta = map[string][]v1.Metadata{}
decoder := current.Object(
current.Key("status", current.Value(func(s string, _ bool) {
Expand Down
9 changes: 9 additions & 0 deletions internal/promapi/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func TestMetadata(t *testing.T) {
w.Header().Set("Content-Type", "application/json")
time.Sleep(time.Second * 2)
_, _ = w.Write([]byte(`{"status":"success","data":{"once":[{"type":"gauge","help":"Text","unit":""}]}}`))
case "empty":
w.WriteHeader(200)
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{}`))
case "error":
w.WriteHeader(500)
_, _ = w.Write([]byte("fake error\n"))
Expand Down Expand Up @@ -99,6 +103,11 @@ func TestMetadata(t *testing.T) {
timeout: time.Millisecond * 10,
err: "connection timeout",
},
{
metric: "empty",
timeout: time.Second,
err: "unknown: empty response object",
},
{
metric: "error",
timeout: time.Second,
Expand Down
1 change: 1 addition & 0 deletions internal/promapi/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func streamSamples(r io.Reader) (samples []Sample, stats QueryStats, err error)
defer dummyReadAll(r)

var status, resultType, errType, errText string
errText = "empty response object"
samples = []Sample{}
var sample model.Sample
decoder := current.Object(
Expand Down
1 change: 1 addition & 0 deletions internal/promapi/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ func streamSampleStream(r io.Reader, step time.Duration) (dst MetricTimeRanges,
defer dummyReadAll(r)

var status, errType, errText, resultType string
errText = "empty response object"
var sample model.SampleStream
decoder := current.Object(
current.Key("status", current.Value(func(s string, _ bool) {
Expand Down

0 comments on commit e9d8514

Please sign in to comment.