diff --git a/internal/promapi/config.go b/internal/promapi/config.go index b95d3b35..e9d534b9 100644 --- a/internal/promapi/config.go +++ b/internal/promapi/config.go @@ -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 diff --git a/internal/promapi/flags.go b/internal/promapi/flags.go index c234f4c4..3f641fd7 100644 --- a/internal/promapi/flags.go +++ b/internal/promapi/flags.go @@ -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) { diff --git a/internal/promapi/metadata.go b/internal/promapi/metadata.go index bef10ed6..563b3fe5 100644 --- a/internal/promapi/metadata.go +++ b/internal/promapi/metadata.go @@ -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) { diff --git a/internal/promapi/metadata_test.go b/internal/promapi/metadata_test.go index d0e1881d..58e12e66 100644 --- a/internal/promapi/metadata_test.go +++ b/internal/promapi/metadata_test.go @@ -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")) @@ -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, diff --git a/internal/promapi/query.go b/internal/promapi/query.go index 5fcc6ee6..5d937269 100644 --- a/internal/promapi/query.go +++ b/internal/promapi/query.go @@ -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( diff --git a/internal/promapi/range.go b/internal/promapi/range.go index 3d19fd78..263acfdb 100644 --- a/internal/promapi/range.go +++ b/internal/promapi/range.go @@ -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) {