|
|
@ -29,7 +29,7 @@ var ( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type ProfilingClient interface { |
|
|
|
type ProfilingClient interface { |
|
|
|
ProfileTypes(context.Context) ([]*ProfileType, error) |
|
|
|
ProfileTypes(ctx context.Context, start int64, end int64) ([]*ProfileType, error) |
|
|
|
LabelNames(ctx context.Context, labelSelector string, start int64, end int64) ([]string, error) |
|
|
|
LabelNames(ctx context.Context, labelSelector string, start int64, end int64) ([]string, error) |
|
|
|
LabelValues(ctx context.Context, label string, labelSelector string, start int64, end int64) ([]string, error) |
|
|
|
LabelValues(ctx context.Context, label string, labelSelector string, start int64, end int64) ([]string, error) |
|
|
|
GetSeries(ctx context.Context, profileTypeID string, labelSelector string, start int64, end int64, groupBy []string, step float64) (*SeriesResponse, error) |
|
|
|
GetSeries(ctx context.Context, profileTypeID string, labelSelector string, start int64, end int64, groupBy []string, step float64) (*SeriesResponse, error) |
|
|
@ -86,7 +86,30 @@ func (d *PyroscopeDatasource) CallResource(ctx context.Context, req *backend.Cal |
|
|
|
|
|
|
|
|
|
|
|
func (d *PyroscopeDatasource) profileTypes(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error { |
|
|
|
func (d *PyroscopeDatasource) profileTypes(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error { |
|
|
|
ctxLogger := logger.FromContext(ctx) |
|
|
|
ctxLogger := logger.FromContext(ctx) |
|
|
|
types, err := d.client.ProfileTypes(ctx) |
|
|
|
|
|
|
|
|
|
|
|
u, err := url.Parse(req.URL) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctxLogger.Error("Failed to parse URL", "error", err, "function", logEntrypoint()) |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
query := u.Query() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var start, end int64 |
|
|
|
|
|
|
|
if query.Has("start") && query.Has("end") { |
|
|
|
|
|
|
|
start, err = strconv.ParseInt(query.Get("start"), 10, 64) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctxLogger.Error("Failed to parse start as int", "error", err, "function", logEntrypoint()) |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end, err = strconv.ParseInt(query.Get("end"), 10, 64) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctxLogger.Error("Failed to parse end as int", "error", err, "function", logEntrypoint()) |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
types, err := d.client.ProfileTypes(ctx, start, end) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctxLogger.Error("Received error from client", "error", err, "function", logEntrypoint()) |
|
|
|
ctxLogger.Error("Received error from client", "error", err, "function", logEntrypoint()) |
|
|
|
return err |
|
|
|
return err |
|
|
@ -199,7 +222,7 @@ func (d *PyroscopeDatasource) labelValues(ctx context.Context, req *backend.Call |
|
|
|
// contains Frames ([]*Frame).
|
|
|
|
// contains Frames ([]*Frame).
|
|
|
|
func (d *PyroscopeDatasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) { |
|
|
|
func (d *PyroscopeDatasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) { |
|
|
|
ctxLogger := logger.FromContext(ctx) |
|
|
|
ctxLogger := logger.FromContext(ctx) |
|
|
|
ctxLogger.Debug("Processing queries", "queryLenght", len(req.Queries), "function", logEntrypoint()) |
|
|
|
ctxLogger.Debug("Processing queries", "queryLength", len(req.Queries), "function", logEntrypoint()) |
|
|
|
|
|
|
|
|
|
|
|
// create response struct
|
|
|
|
// create response struct
|
|
|
|
response := backend.NewQueryDataResponse() |
|
|
|
response := backend.NewQueryDataResponse() |
|
|
@ -228,7 +251,11 @@ func (d *PyroscopeDatasource) CheckHealth(ctx context.Context, _ *backend.CheckH |
|
|
|
status := backend.HealthStatusOk |
|
|
|
status := backend.HealthStatusOk |
|
|
|
message := "Data source is working" |
|
|
|
message := "Data source is working" |
|
|
|
|
|
|
|
|
|
|
|
if _, err := d.client.ProfileTypes(ctx); err != nil { |
|
|
|
// Since this is a health check mechanism and we only care about whether the
|
|
|
|
|
|
|
|
// request succeeded or failed, we set the window to be small.
|
|
|
|
|
|
|
|
start := time.Now().Add(-5 * time.Minute).UnixMilli() |
|
|
|
|
|
|
|
end := time.Now().UnixMilli() |
|
|
|
|
|
|
|
if _, err := d.client.ProfileTypes(ctx, start, end); err != nil { |
|
|
|
status = backend.HealthStatusError |
|
|
|
status = backend.HealthStatusError |
|
|
|
message = err.Error() |
|
|
|
message = err.Error() |
|
|
|
} |
|
|
|
} |
|
|
|