mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-12 16:44:05 -08:00
Print details of API errors
Signed-off-by: Łukasz Hryniuk <code@hryniuk.pl>
This commit is contained in:
parent
4fca1b9f5d
commit
ab41de68b4
|
@ -497,8 +497,7 @@ func QueryInstant(url *url.URL, query, evalTime string, p printer) int {
|
||||||
val, _, err := api.Query(ctx, query, eTime) // Ignoring warnings for now.
|
val, _, err := api.Query(ctx, query, eTime) // Ignoring warnings for now.
|
||||||
cancel()
|
cancel()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "query error:", err)
|
return handleAPIError(err)
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p.printValue(val)
|
p.printValue(val)
|
||||||
|
@ -572,8 +571,7 @@ func QueryRange(url *url.URL, headers map[string]string, query, start, end strin
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "query error:", err)
|
return handleAPIError(err)
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p.printValue(val)
|
p.printValue(val)
|
||||||
|
@ -609,8 +607,7 @@ func QuerySeries(url *url.URL, matchers []string, start, end string, p printer)
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "query error:", err)
|
return handleAPIError(err)
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p.printSeries(val)
|
p.printSeries(val)
|
||||||
|
@ -648,16 +645,25 @@ func QueryLabels(url *url.URL, name string, start, end string, p printer) int {
|
||||||
for _, v := range warn {
|
for _, v := range warn {
|
||||||
fmt.Fprintln(os.Stderr, "query warning:", v)
|
fmt.Fprintln(os.Stderr, "query warning:", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "query error:", err)
|
return handleAPIError(err)
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p.printLabelValues(val)
|
p.printLabelValues(val)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleAPIError(err error) int {
|
||||||
|
var apiErr *v1.Error
|
||||||
|
if errors.As(err, &apiErr) && apiErr.Detail != "" {
|
||||||
|
fmt.Fprintf(os.Stderr, "query error: %v (detail: %s)\n", apiErr, strings.TrimSpace(apiErr.Detail))
|
||||||
|
} else {
|
||||||
|
fmt.Fprintln(os.Stderr, "query error:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
func parseStartTimeAndEndTime(start, end string) (time.Time, time.Time, error) {
|
func parseStartTimeAndEndTime(start, end string) (time.Time, time.Time, error) {
|
||||||
var (
|
var (
|
||||||
minTime = time.Now().Add(-9999 * time.Hour)
|
minTime = time.Now().Add(-9999 * time.Hour)
|
||||||
|
|
Loading…
Reference in a new issue