Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback error text #1013

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading