-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DebugAPI implements the API interface and simply adds debug/trace logging to all calls made through it. This way we can get nice debug messages such as: ``` DEBU[2019-06-07T08:15:27-07:00] http://localhost:9090/api/v1/read api=GetValue end="2019-06-07 08:11:33.855 -0700 PDT" matchers="[__name__=\"prometheus_api_remote_read_queries\"]" start="2019-06-07 07:06:33.855 -0700 PDT" ``` To avoid the performance overhead this layer is only added when the log level is >= debug. Fixes #163
- Loading branch information
Showing
2 changed files
with
141 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package promclient | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
v1 "github.com/prometheus/client_golang/api/prometheus/v1" | ||
"github.com/prometheus/common/model" | ||
"github.com/prometheus/prometheus/pkg/labels" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// DebugAPI simply logs debug lines for the given API with the given prefix | ||
type DebugAPI struct { | ||
API | ||
PrefixMessage string | ||
} | ||
|
||
// LabelValues performs a query for the values of the given label. | ||
func (d *DebugAPI) LabelValues(ctx context.Context, label string) (model.LabelValues, error) { | ||
logrus.WithFields(logrus.Fields{ | ||
"api": "LabelValues", | ||
"label": label, | ||
}).Debug(d.PrefixMessage) | ||
|
||
v, err := d.API.LabelValues(ctx, label) | ||
|
||
logrus.WithFields(logrus.Fields{ | ||
"api": "LabelValues", | ||
"label": label, | ||
"value": v, | ||
"error": err, | ||
}).Trace(d.PrefixMessage) | ||
|
||
return v, err | ||
} | ||
|
||
// Query performs a query for the given time. | ||
func (d *DebugAPI) Query(ctx context.Context, query string, ts time.Time) (model.Value, error) { | ||
logrus.WithFields(logrus.Fields{ | ||
"api": "Query", | ||
"query": query, | ||
"ts": ts, | ||
}).Debug(d.PrefixMessage) | ||
|
||
v, err := d.API.Query(ctx, query, ts) | ||
|
||
logrus.WithFields(logrus.Fields{ | ||
"api": "Query", | ||
"query": query, | ||
"ts": ts, | ||
"value": v, | ||
"error": err, | ||
}).Trace(d.PrefixMessage) | ||
|
||
return v, err | ||
} | ||
|
||
// QueryRange performs a query for the given range. | ||
func (d *DebugAPI) QueryRange(ctx context.Context, query string, r v1.Range) (model.Value, error) { | ||
fmt.Println("what") | ||
logrus.WithFields(logrus.Fields{ | ||
"api": "QueryRange", | ||
"query": query, | ||
"r": r, | ||
}).Debug(d.PrefixMessage) | ||
|
||
v, err := d.API.QueryRange(ctx, query, r) | ||
|
||
logrus.WithFields(logrus.Fields{ | ||
"api": "QueryRange", | ||
"query": query, | ||
"r": r, | ||
"value": v, | ||
"error": err, | ||
}).Trace(d.PrefixMessage) | ||
|
||
return v, err | ||
} | ||
|
||
// Series finds series by label matchers. | ||
func (d *DebugAPI) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, error) { | ||
logrus.WithFields(logrus.Fields{ | ||
"api": "Series", | ||
"matches": matches, | ||
"startTime": startTime, | ||
"endTime": endTime, | ||
}).Debug(d.PrefixMessage) | ||
|
||
v, err := d.API.Series(ctx, matches, startTime, endTime) | ||
|
||
logrus.WithFields(logrus.Fields{ | ||
"api": "Series", | ||
"matches": matches, | ||
"startTime": startTime, | ||
"endTime": endTime, | ||
"value": v, | ||
"error": err, | ||
}).Trace(d.PrefixMessage) | ||
|
||
return v, err | ||
} | ||
|
||
// GetValue loads the raw data for a given set of matchers in the time range | ||
func (d *DebugAPI) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) (model.Value, error) { | ||
logrus.WithFields(logrus.Fields{ | ||
"api": "GetValue", | ||
"start": start, | ||
"end": end, | ||
"matchers": matchers, | ||
}).Debug(d.PrefixMessage) | ||
|
||
v, err := d.API.GetValue(ctx, start, end, matchers) | ||
|
||
logrus.WithFields(logrus.Fields{ | ||
"api": "GetValue", | ||
"start": start, | ||
"end": end, | ||
"matchers": matchers, | ||
"value": v, | ||
"error": err, | ||
}).Trace(d.PrefixMessage) | ||
|
||
return v, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters