mirror of https://github.com/grafana/grafana.git
				
				
				
			Profiles: Stop passing response headers for Grafana-Pyroscope and parca datasources (#106577)
* Revert "pkgs/tsdb/[grafana-pyroscope-datasource|parca]: Fix use of request headers in responses"
This reverts commit 8bac68e906.
* Profiles: Stop passing request/response headers to the backend
			
			
This commit is contained in:
		
							parent
							
								
									4f127c6dff
								
							
						
					
					
						commit
						8fdf86e56f
					
				|  | @ -29,12 +29,12 @@ var ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type ProfilingClient interface { | type ProfilingClient interface { | ||||||
| 	ProfileTypes(ctx context.Context, start int64, end int64) ([]*ProfileType, http.Header, error) | 	ProfileTypes(ctx context.Context, start int64, end int64) ([]*ProfileType, error) | ||||||
| 	LabelNames(ctx context.Context, labelSelector string, start int64, end int64) ([]string, http.Header, 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, http.Header, 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, limit *int64, step float64) (*SeriesResponse, http.Header, error) | 	GetSeries(ctx context.Context, profileTypeID string, labelSelector string, start int64, end int64, groupBy []string, limit *int64, step float64) (*SeriesResponse, error) | ||||||
| 	GetProfile(ctx context.Context, profileTypeID string, labelSelector string, start int64, end int64, maxNodes *int64) (*ProfileResponse, http.Header, error) | 	GetProfile(ctx context.Context, profileTypeID string, labelSelector string, start int64, end int64, maxNodes *int64) (*ProfileResponse, error) | ||||||
| 	GetSpanProfile(ctx context.Context, profileTypeID string, labelSelector string, spanSelector []string, start int64, end int64, maxNodes *int64) (*ProfileResponse, http.Header, error) | 	GetSpanProfile(ctx context.Context, profileTypeID string, labelSelector string, spanSelector []string, start int64, end int64, maxNodes *int64) (*ProfileResponse, error) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // PyroscopeDatasource is a datasource for querying application performance profiles.
 | // PyroscopeDatasource is a datasource for querying application performance profiles.
 | ||||||
|  | @ -109,7 +109,7 @@ func (d *PyroscopeDatasource) profileTypes(ctx context.Context, req *backend.Cal | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	types, respHeaders, err := d.client.ProfileTypes(ctx, start, end) | 	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 | ||||||
|  | @ -119,7 +119,7 @@ func (d *PyroscopeDatasource) profileTypes(ctx context.Context, req *backend.Cal | ||||||
| 		ctxLogger.Error("Failed to marshal response", "error", err, "function", logEntrypoint()) | 		ctxLogger.Error("Failed to marshal response", "error", err, "function", logEntrypoint()) | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	err = sender.Send(&backend.CallResourceResponse{Body: bodyData, Headers: respHeaders, Status: 200}) | 	err = sender.Send(&backend.CallResourceResponse{Body: bodyData, Status: 200}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		ctxLogger.Error("Failed to send response", "error", err, "function", logEntrypoint()) | 		ctxLogger.Error("Failed to send response", "error", err, "function", logEntrypoint()) | ||||||
| 		return err | 		return err | ||||||
|  | @ -146,7 +146,7 @@ func (d *PyroscopeDatasource) labelNames(ctx context.Context, req *backend.CallR | ||||||
| 		return fmt.Errorf("failed parsing label selector: %v", err) | 		return fmt.Errorf("failed parsing label selector: %v", err) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	labelNames, respHeaders, err := d.client.LabelNames(ctx, labelSelector, start, end) | 	labelNames, err := d.client.LabelNames(ctx, labelSelector, 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 fmt.Errorf("error calling LabelNames: %v", err) | 		return fmt.Errorf("error calling LabelNames: %v", err) | ||||||
|  | @ -167,7 +167,7 @@ func (d *PyroscopeDatasource) labelNames(ctx context.Context, req *backend.CallR | ||||||
| 		ctxLogger.Error("Failed to marshal response", "error", err, "function", logEntrypoint()) | 		ctxLogger.Error("Failed to marshal response", "error", err, "function", logEntrypoint()) | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	err = sender.Send(&backend.CallResourceResponse{Body: jsonResponse, Headers: respHeaders, Status: 200}) | 	err = sender.Send(&backend.CallResourceResponse{Body: jsonResponse, Status: 200}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		ctxLogger.Error("Failed to send response", "error", err, "function", logEntrypoint()) | 		ctxLogger.Error("Failed to send response", "error", err, "function", logEntrypoint()) | ||||||
| 		return err | 		return err | ||||||
|  | @ -195,7 +195,7 @@ func (d *PyroscopeDatasource) labelValues(ctx context.Context, req *backend.Call | ||||||
| 	end, _ := strconv.ParseInt(query.Get("end"), 10, 64) | 	end, _ := strconv.ParseInt(query.Get("end"), 10, 64) | ||||||
| 	label := query.Get("label") | 	label := query.Get("label") | ||||||
| 
 | 
 | ||||||
| 	res, respHeaders, err := d.client.LabelValues(ctx, label, query.Get("query"), start, end) | 	res, err := d.client.LabelValues(ctx, label, query.Get("query"), 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 fmt.Errorf("error calling LabelValues: %v", err) | 		return fmt.Errorf("error calling LabelValues: %v", err) | ||||||
|  | @ -207,7 +207,7 @@ func (d *PyroscopeDatasource) labelValues(ctx context.Context, req *backend.Call | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	err = sender.Send(&backend.CallResourceResponse{Body: data, Headers: respHeaders, Status: 200}) | 	err = sender.Send(&backend.CallResourceResponse{Body: data, Status: 200}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		ctxLogger.Error("Failed to send response", "error", err, "function", logEntrypoint()) | 		ctxLogger.Error("Failed to send response", "error", err, "function", logEntrypoint()) | ||||||
| 		return err | 		return err | ||||||
|  | @ -255,7 +255,7 @@ func (d *PyroscopeDatasource) CheckHealth(ctx context.Context, _ *backend.CheckH | ||||||
| 	// request succeeded or failed, we set the window to be small.
 | 	// request succeeded or failed, we set the window to be small.
 | ||||||
| 	start := time.Unix(1, 0).UnixMilli() | 	start := time.Unix(1, 0).UnixMilli() | ||||||
| 	end := time.Unix(4, 0).UnixMilli() | 	end := time.Unix(4, 0).UnixMilli() | ||||||
| 	if _, _, err := d.client.ProfileTypes(ctx, start, end); err != nil { | 	if _, err := d.client.ProfileTypes(ctx, start, end); err != nil { | ||||||
| 		status = backend.HealthStatusError | 		status = backend.HealthStatusError | ||||||
| 		message = err.Error() | 		message = err.Error() | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -71,7 +71,7 @@ func NewPyroscopeClient(httpClient *http.Client, url string) *PyroscopeClient { | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *PyroscopeClient) ProfileTypes(ctx context.Context, start int64, end int64) ([]*ProfileType, http.Header, error) { | func (c *PyroscopeClient) ProfileTypes(ctx context.Context, start int64, end int64) ([]*ProfileType, error) { | ||||||
| 	ctx, span := tracing.DefaultTracer().Start(ctx, "datasource.pyroscope.ProfileTypes") | 	ctx, span := tracing.DefaultTracer().Start(ctx, "datasource.pyroscope.ProfileTypes") | ||||||
| 	defer span.End() | 	defer span.End() | ||||||
| 	res, err := c.connectClient.ProfileTypes(ctx, connect.NewRequest(&querierv1.ProfileTypesRequest{ | 	res, err := c.connectClient.ProfileTypes(ctx, connect.NewRequest(&querierv1.ProfileTypesRequest{ | ||||||
|  | @ -82,11 +82,11 @@ func (c *PyroscopeClient) ProfileTypes(ctx context.Context, start int64, end int | ||||||
| 		logger.Error("Received error from client", "error", err, "function", logEntrypoint()) | 		logger.Error("Received error from client", "error", err, "function", logEntrypoint()) | ||||||
| 		span.RecordError(err) | 		span.RecordError(err) | ||||||
| 		span.SetStatus(codes.Error, err.Error()) | 		span.SetStatus(codes.Error, err.Error()) | ||||||
| 		return nil, nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	if res.Msg.ProfileTypes == nil { | 	if res.Msg.ProfileTypes == nil { | ||||||
| 		// Let's make sure we send at least empty array if we don't have any types
 | 		// Let's make sure we send at least empty array if we don't have any types
 | ||||||
| 		return []*ProfileType{}, nil, nil | 		return []*ProfileType{}, nil | ||||||
| 	} else { | 	} else { | ||||||
| 		pTypes := make([]*ProfileType, len(res.Msg.ProfileTypes)) | 		pTypes := make([]*ProfileType, len(res.Msg.ProfileTypes)) | ||||||
| 		for i, pType := range res.Msg.ProfileTypes { | 		for i, pType := range res.Msg.ProfileTypes { | ||||||
|  | @ -95,11 +95,11 @@ func (c *PyroscopeClient) ProfileTypes(ctx context.Context, start int64, end int | ||||||
| 				Label: pType.Name + " - " + pType.SampleType, | 				Label: pType.Name + " - " + pType.SampleType, | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		return pTypes, res.Header(), nil | 		return pTypes, nil | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *PyroscopeClient) GetSeries(ctx context.Context, profileTypeID string, labelSelector string, start int64, end int64, groupBy []string, limit *int64, step float64) (*SeriesResponse, http.Header, error) { | func (c *PyroscopeClient) GetSeries(ctx context.Context, profileTypeID string, labelSelector string, start int64, end int64, groupBy []string, limit *int64, step float64) (*SeriesResponse, error) { | ||||||
| 	ctx, span := tracing.DefaultTracer().Start(ctx, "datasource.pyroscope.GetSeries", trace.WithAttributes(attribute.String("profileTypeID", profileTypeID), attribute.String("labelSelector", labelSelector))) | 	ctx, span := tracing.DefaultTracer().Start(ctx, "datasource.pyroscope.GetSeries", trace.WithAttributes(attribute.String("profileTypeID", profileTypeID), attribute.String("labelSelector", labelSelector))) | ||||||
| 	defer span.End() | 	defer span.End() | ||||||
| 	req := connect.NewRequest(&querierv1.SelectSeriesRequest{ | 	req := connect.NewRequest(&querierv1.SelectSeriesRequest{ | ||||||
|  | @ -117,7 +117,7 @@ func (c *PyroscopeClient) GetSeries(ctx context.Context, profileTypeID string, l | ||||||
| 		logger.Error("Received error from client", "error", err, "function", logEntrypoint()) | 		logger.Error("Received error from client", "error", err, "function", logEntrypoint()) | ||||||
| 		span.RecordError(err) | 		span.RecordError(err) | ||||||
| 		span.SetStatus(codes.Error, err.Error()) | 		span.SetStatus(codes.Error, err.Error()) | ||||||
| 		return nil, nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	series := make([]*Series, len(resp.Msg.Series)) | 	series := make([]*Series, len(resp.Msg.Series)) | ||||||
|  | @ -152,10 +152,10 @@ func (c *PyroscopeClient) GetSeries(ctx context.Context, profileTypeID string, l | ||||||
| 		Series: series, | 		Series: series, | ||||||
| 		Units:  getUnits(profileTypeID), | 		Units:  getUnits(profileTypeID), | ||||||
| 		Label:  parts[1], | 		Label:  parts[1], | ||||||
| 	}, resp.Header(), nil | 	}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *PyroscopeClient) GetProfile(ctx context.Context, profileTypeID, labelSelector string, start, end int64, maxNodes *int64) (*ProfileResponse, http.Header, error) { | func (c *PyroscopeClient) GetProfile(ctx context.Context, profileTypeID, labelSelector string, start, end int64, maxNodes *int64) (*ProfileResponse, error) { | ||||||
| 	ctx, span := tracing.DefaultTracer().Start(ctx, "datasource.pyroscope.GetProfile", trace.WithAttributes(attribute.String("profileTypeID", profileTypeID), attribute.String("labelSelector", labelSelector))) | 	ctx, span := tracing.DefaultTracer().Start(ctx, "datasource.pyroscope.GetProfile", trace.WithAttributes(attribute.String("profileTypeID", profileTypeID), attribute.String("labelSelector", labelSelector))) | ||||||
| 	defer span.End() | 	defer span.End() | ||||||
| 	req := &connect.Request[querierv1.SelectMergeStacktracesRequest]{ | 	req := &connect.Request[querierv1.SelectMergeStacktracesRequest]{ | ||||||
|  | @ -173,18 +173,18 @@ func (c *PyroscopeClient) GetProfile(ctx context.Context, profileTypeID, labelSe | ||||||
| 		logger.Error("Received error from client", "error", err, "function", logEntrypoint()) | 		logger.Error("Received error from client", "error", err, "function", logEntrypoint()) | ||||||
| 		span.RecordError(err) | 		span.RecordError(err) | ||||||
| 		span.SetStatus(codes.Error, err.Error()) | 		span.SetStatus(codes.Error, err.Error()) | ||||||
| 		return nil, nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if resp.Msg.Flamegraph == nil { | 	if resp.Msg.Flamegraph == nil { | ||||||
| 		// Not an error, can happen when querying data oout of range.
 | 		// Not an error, can happen when querying data oout of range.
 | ||||||
| 		return nil, nil, nil | 		return nil, nil | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return profileQuery(resp.Msg.Flamegraph, profileTypeID), resp.Header(), nil | 	return profileQuery(ctx, err, span, resp.Msg.Flamegraph, profileTypeID) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *PyroscopeClient) GetSpanProfile(ctx context.Context, profileTypeID, labelSelector string, spanSelector []string, start, end int64, maxNodes *int64) (*ProfileResponse, http.Header, error) { | func (c *PyroscopeClient) GetSpanProfile(ctx context.Context, profileTypeID, labelSelector string, spanSelector []string, start, end int64, maxNodes *int64) (*ProfileResponse, error) { | ||||||
| 	ctx, span := tracing.DefaultTracer().Start(ctx, "datasource.pyroscope.GetSpanProfile", trace.WithAttributes(attribute.String("profileTypeID", profileTypeID), attribute.String("labelSelector", labelSelector), attribute.String("spanSelector", strings.Join(spanSelector, ",")))) | 	ctx, span := tracing.DefaultTracer().Start(ctx, "datasource.pyroscope.GetSpanProfile", trace.WithAttributes(attribute.String("profileTypeID", profileTypeID), attribute.String("labelSelector", labelSelector), attribute.String("spanSelector", strings.Join(spanSelector, ",")))) | ||||||
| 	defer span.End() | 	defer span.End() | ||||||
| 	req := &connect.Request[querierv1.SelectMergeSpanProfileRequest]{ | 	req := &connect.Request[querierv1.SelectMergeSpanProfileRequest]{ | ||||||
|  | @ -202,18 +202,18 @@ func (c *PyroscopeClient) GetSpanProfile(ctx context.Context, profileTypeID, lab | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		span.RecordError(err) | 		span.RecordError(err) | ||||||
| 		span.SetStatus(codes.Error, err.Error()) | 		span.SetStatus(codes.Error, err.Error()) | ||||||
| 		return nil, nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if resp.Msg.Flamegraph == nil { | 	if resp.Msg.Flamegraph == nil { | ||||||
| 		// Not an error, can happen when querying data oout of range.
 | 		// Not an error, can happen when querying data oout of range.
 | ||||||
| 		return nil, nil, nil | 		return nil, nil | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return profileQuery(resp.Msg.Flamegraph, profileTypeID), resp.Header(), nil | 	return profileQuery(ctx, err, span, resp.Msg.Flamegraph, profileTypeID) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func profileQuery(flamegraph *querierv1.FlameGraph, profileTypeID string) *ProfileResponse { | func profileQuery(ctx context.Context, err error, span trace.Span, flamegraph *querierv1.FlameGraph, profileTypeID string) (*ProfileResponse, error) { | ||||||
| 	levels := make([]*Level, len(flamegraph.Levels)) | 	levels := make([]*Level, len(flamegraph.Levels)) | ||||||
| 	for i, level := range flamegraph.Levels { | 	for i, level := range flamegraph.Levels { | ||||||
| 		levels[i] = &Level{ | 		levels[i] = &Level{ | ||||||
|  | @ -229,7 +229,7 @@ func profileQuery(flamegraph *querierv1.FlameGraph, profileTypeID string) *Profi | ||||||
| 			MaxSelf: flamegraph.MaxSelf, | 			MaxSelf: flamegraph.MaxSelf, | ||||||
| 		}, | 		}, | ||||||
| 		Units: getUnits(profileTypeID), | 		Units: getUnits(profileTypeID), | ||||||
| 	} | 	}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func getUnits(profileTypeID string) string { | func getUnits(profileTypeID string) string { | ||||||
|  | @ -244,7 +244,7 @@ func getUnits(profileTypeID string) string { | ||||||
| 	return unit | 	return unit | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *PyroscopeClient) LabelNames(ctx context.Context, labelSelector string, start int64, end int64) ([]string, http.Header, error) { | func (c *PyroscopeClient) LabelNames(ctx context.Context, labelSelector string, start int64, end int64) ([]string, error) { | ||||||
| 	ctx, span := tracing.DefaultTracer().Start(ctx, "datasource.pyroscope.LabelNames") | 	ctx, span := tracing.DefaultTracer().Start(ctx, "datasource.pyroscope.LabelNames") | ||||||
| 	defer span.End() | 	defer span.End() | ||||||
| 	resp, err := c.connectClient.LabelNames(ctx, connect.NewRequest(&typesv1.LabelNamesRequest{ | 	resp, err := c.connectClient.LabelNames(ctx, connect.NewRequest(&typesv1.LabelNamesRequest{ | ||||||
|  | @ -256,11 +256,11 @@ func (c *PyroscopeClient) LabelNames(ctx context.Context, labelSelector string, | ||||||
| 		logger.Error("Received error from client", "error", err, "function", logEntrypoint()) | 		logger.Error("Received error from client", "error", err, "function", logEntrypoint()) | ||||||
| 		span.RecordError(err) | 		span.RecordError(err) | ||||||
| 		span.SetStatus(codes.Error, err.Error()) | 		span.SetStatus(codes.Error, err.Error()) | ||||||
| 		return nil, nil, fmt.Errorf("error sending LabelNames request %v", err) | 		return nil, fmt.Errorf("error sending LabelNames request %v", err) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if resp.Msg.Names == nil { | 	if resp.Msg.Names == nil { | ||||||
| 		return []string{}, nil, nil | 		return []string{}, nil | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	var filtered []string | 	var filtered []string | ||||||
|  | @ -270,10 +270,10 @@ func (c *PyroscopeClient) LabelNames(ctx context.Context, labelSelector string, | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return filtered, resp.Header(), nil | 	return filtered, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *PyroscopeClient) LabelValues(ctx context.Context, label string, labelSelector string, start int64, end int64) ([]string, http.Header, error) { | func (c *PyroscopeClient) LabelValues(ctx context.Context, label string, labelSelector string, start int64, end int64) ([]string, error) { | ||||||
| 	ctx, span := tracing.DefaultTracer().Start(ctx, "datasource.pyroscope.LabelValues") | 	ctx, span := tracing.DefaultTracer().Start(ctx, "datasource.pyroscope.LabelValues") | ||||||
| 	defer span.End() | 	defer span.End() | ||||||
| 	resp, err := c.connectClient.LabelValues(ctx, connect.NewRequest(&typesv1.LabelValuesRequest{ | 	resp, err := c.connectClient.LabelValues(ctx, connect.NewRequest(&typesv1.LabelValuesRequest{ | ||||||
|  | @ -286,12 +286,12 @@ func (c *PyroscopeClient) LabelValues(ctx context.Context, label string, labelSe | ||||||
| 		logger.Error("Received error from client", "error", err, "function", logEntrypoint()) | 		logger.Error("Received error from client", "error", err, "function", logEntrypoint()) | ||||||
| 		span.RecordError(err) | 		span.RecordError(err) | ||||||
| 		span.SetStatus(codes.Error, err.Error()) | 		span.SetStatus(codes.Error, err.Error()) | ||||||
| 		return nil, nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	if resp.Msg.Names == nil { | 	if resp.Msg.Names == nil { | ||||||
| 		return []string{}, nil, nil | 		return []string{}, nil | ||||||
| 	} | 	} | ||||||
| 	return resp.Msg.Names, resp.Header(), nil | 	return resp.Msg.Names, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func isPrivateLabel(label string) bool { | func isPrivateLabel(label string) bool { | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ func Test_PyroscopeClient(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 	t.Run("GetSeries", func(t *testing.T) { | 	t.Run("GetSeries", func(t *testing.T) { | ||||||
| 		limit := int64(42) | 		limit := int64(42) | ||||||
| 		resp, _, err := client.GetSeries(context.Background(), "memory:alloc_objects:count:space:bytes", "{}", 0, 100, []string{}, &limit, 15) | 		resp, err := client.GetSeries(context.Background(), "memory:alloc_objects:count:space:bytes", "{}", 0, 100, []string{}, &limit, 15) | ||||||
| 		require.Nil(t, err) | 		require.Nil(t, err) | ||||||
| 
 | 
 | ||||||
| 		series := &SeriesResponse{ | 		series := &SeriesResponse{ | ||||||
|  | @ -34,7 +34,7 @@ func Test_PyroscopeClient(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 	t.Run("GetProfile", func(t *testing.T) { | 	t.Run("GetProfile", func(t *testing.T) { | ||||||
| 		maxNodes := int64(-1) | 		maxNodes := int64(-1) | ||||||
| 		resp, _, err := client.GetProfile(context.Background(), "memory:alloc_objects:count:space:bytes", "{}", 0, 100, &maxNodes) | 		resp, err := client.GetProfile(context.Background(), "memory:alloc_objects:count:space:bytes", "{}", 0, 100, &maxNodes) | ||||||
| 		require.Nil(t, err) | 		require.Nil(t, err) | ||||||
| 
 | 
 | ||||||
| 		series := &ProfileResponse{ | 		series := &ProfileResponse{ | ||||||
|  | @ -56,7 +56,7 @@ func Test_PyroscopeClient(t *testing.T) { | ||||||
| 	t.Run("GetProfile with empty response", func(t *testing.T) { | 	t.Run("GetProfile with empty response", func(t *testing.T) { | ||||||
| 		connectClient.SendEmptyProfileResponse = true | 		connectClient.SendEmptyProfileResponse = true | ||||||
| 		maxNodes := int64(-1) | 		maxNodes := int64(-1) | ||||||
| 		resp, _, err := client.GetProfile(context.Background(), "memory:alloc_objects:count:space:bytes", "{}", 0, 100, &maxNodes) | 		resp, err := client.GetProfile(context.Background(), "memory:alloc_objects:count:space:bytes", "{}", 0, 100, &maxNodes) | ||||||
| 		require.Nil(t, err) | 		require.Nil(t, err) | ||||||
| 		// Mainly ensuring this does not panic like before
 | 		// Mainly ensuring this does not panic like before
 | ||||||
| 		require.Nil(t, resp) | 		require.Nil(t, resp) | ||||||
|  |  | ||||||
|  | @ -77,7 +77,7 @@ func (d *PyroscopeDatasource) query(ctx context.Context, pCtx backend.PluginCont | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 			logger.Debug("Sending SelectSeriesRequest", "queryModel", qm, "function", logEntrypoint()) | 			logger.Debug("Sending SelectSeriesRequest", "queryModel", qm, "function", logEntrypoint()) | ||||||
| 			seriesResp, _, err := d.client.GetSeries( | 			seriesResp, err := d.client.GetSeries( | ||||||
| 				gCtx, | 				gCtx, | ||||||
| 				profileTypeId, | 				profileTypeId, | ||||||
| 				labelSelector, | 				labelSelector, | ||||||
|  | @ -114,7 +114,7 @@ func (d *PyroscopeDatasource) query(ctx context.Context, pCtx backend.PluginCont | ||||||
| 			var profileResp *ProfileResponse | 			var profileResp *ProfileResponse | ||||||
| 			if len(qm.SpanSelector) > 0 { | 			if len(qm.SpanSelector) > 0 { | ||||||
| 				logger.Debug("Calling GetSpanProfile", "queryModel", qm, "function", logEntrypoint()) | 				logger.Debug("Calling GetSpanProfile", "queryModel", qm, "function", logEntrypoint()) | ||||||
| 				prof, _, err := d.client.GetSpanProfile(gCtx, profileTypeId, labelSelector, qm.SpanSelector, query.TimeRange.From.UnixMilli(), query.TimeRange.To.UnixMilli(), qm.MaxNodes) | 				prof, err := d.client.GetSpanProfile(gCtx, profileTypeId, labelSelector, qm.SpanSelector, query.TimeRange.From.UnixMilli(), query.TimeRange.To.UnixMilli(), qm.MaxNodes) | ||||||
| 				if err != nil { | 				if err != nil { | ||||||
| 					span.RecordError(err) | 					span.RecordError(err) | ||||||
| 					span.SetStatus(codes.Error, err.Error()) | 					span.SetStatus(codes.Error, err.Error()) | ||||||
|  | @ -124,7 +124,7 @@ func (d *PyroscopeDatasource) query(ctx context.Context, pCtx backend.PluginCont | ||||||
| 				profileResp = prof | 				profileResp = prof | ||||||
| 			} else { | 			} else { | ||||||
| 				logger.Debug("Calling GetProfile", "queryModel", qm, "function", logEntrypoint()) | 				logger.Debug("Calling GetProfile", "queryModel", qm, "function", logEntrypoint()) | ||||||
| 				prof, _, err := d.client.GetProfile(gCtx, profileTypeId, labelSelector, query.TimeRange.From.UnixMilli(), query.TimeRange.To.UnixMilli(), qm.MaxNodes) | 				prof, err := d.client.GetProfile(gCtx, profileTypeId, labelSelector, query.TimeRange.From.UnixMilli(), query.TimeRange.To.UnixMilli(), qm.MaxNodes) | ||||||
| 				if err != nil { | 				if err != nil { | ||||||
| 					span.RecordError(err) | 					span.RecordError(err) | ||||||
| 					span.SetStatus(codes.Error, err.Error()) | 					span.SetStatus(codes.Error, err.Error()) | ||||||
|  |  | ||||||
|  | @ -2,7 +2,6 @@ package pyroscope | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"net/http" |  | ||||||
| 	"testing" | 	"testing" | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
|  | @ -419,7 +418,7 @@ type FakeClient struct { | ||||||
| 	Args []any | 	Args []any | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (f *FakeClient) ProfileTypes(ctx context.Context, start int64, end int64) ([]*ProfileType, http.Header, error) { | func (f *FakeClient) ProfileTypes(ctx context.Context, start int64, end int64) ([]*ProfileType, error) { | ||||||
| 	return []*ProfileType{ | 	return []*ProfileType{ | ||||||
| 		{ | 		{ | ||||||
| 			ID:    "type:1", | 			ID:    "type:1", | ||||||
|  | @ -429,18 +428,18 @@ func (f *FakeClient) ProfileTypes(ctx context.Context, start int64, end int64) ( | ||||||
| 			ID:    "type:2", | 			ID:    "type:2", | ||||||
| 			Label: "memory", | 			Label: "memory", | ||||||
| 		}, | 		}, | ||||||
| 	}, http.Header{}, nil | 	}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (f *FakeClient) LabelValues(ctx context.Context, label string, labelSelector string, start int64, end int64) ([]string, http.Header, error) { | func (f *FakeClient) LabelValues(ctx context.Context, label string, labelSelector string, start int64, end int64) ([]string, error) { | ||||||
| 	panic("implement me") | 	panic("implement me") | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (f *FakeClient) LabelNames(ctx context.Context, labelSelector string, start int64, end int64) ([]string, http.Header, error) { | func (f *FakeClient) LabelNames(ctx context.Context, labelSelector string, start int64, end int64) ([]string, error) { | ||||||
| 	panic("implement me") | 	panic("implement me") | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (f *FakeClient) GetProfile(ctx context.Context, profileTypeID, labelSelector string, start, end int64, maxNodes *int64) (*ProfileResponse, http.Header, error) { | func (f *FakeClient) GetProfile(ctx context.Context, profileTypeID, labelSelector string, start, end int64, maxNodes *int64) (*ProfileResponse, error) { | ||||||
| 	return &ProfileResponse{ | 	return &ProfileResponse{ | ||||||
| 		Flamebearer: &Flamebearer{ | 		Flamebearer: &Flamebearer{ | ||||||
| 			Names: []string{"foo", "bar", "baz"}, | 			Names: []string{"foo", "bar", "baz"}, | ||||||
|  | @ -453,10 +452,10 @@ func (f *FakeClient) GetProfile(ctx context.Context, profileTypeID, labelSelecto | ||||||
| 			MaxSelf: 56, | 			MaxSelf: 56, | ||||||
| 		}, | 		}, | ||||||
| 		Units: "count", | 		Units: "count", | ||||||
| 	}, http.Header{}, nil | 	}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (f *FakeClient) GetSpanProfile(ctx context.Context, profileTypeID, labelSelector string, spanSelector []string, start, end int64, maxNodes *int64) (*ProfileResponse, http.Header, error) { | func (f *FakeClient) GetSpanProfile(ctx context.Context, profileTypeID, labelSelector string, spanSelector []string, start, end int64, maxNodes *int64) (*ProfileResponse, error) { | ||||||
| 	return &ProfileResponse{ | 	return &ProfileResponse{ | ||||||
| 		Flamebearer: &Flamebearer{ | 		Flamebearer: &Flamebearer{ | ||||||
| 			Names: []string{"foo", "bar", "baz"}, | 			Names: []string{"foo", "bar", "baz"}, | ||||||
|  | @ -469,10 +468,10 @@ func (f *FakeClient) GetSpanProfile(ctx context.Context, profileTypeID, labelSel | ||||||
| 			MaxSelf: 56, | 			MaxSelf: 56, | ||||||
| 		}, | 		}, | ||||||
| 		Units: "count", | 		Units: "count", | ||||||
| 	}, http.Header{}, nil | 	}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (f *FakeClient) GetSeries(ctx context.Context, profileTypeID, labelSelector string, start, end int64, groupBy []string, limit *int64, step float64) (*SeriesResponse, http.Header, error) { | func (f *FakeClient) GetSeries(ctx context.Context, profileTypeID, labelSelector string, start, end int64, groupBy []string, limit *int64, step float64) (*SeriesResponse, error) { | ||||||
| 	f.Args = []any{profileTypeID, labelSelector, start, end, groupBy, step} | 	f.Args = []any{profileTypeID, labelSelector, start, end, groupBy, step} | ||||||
| 	return &SeriesResponse{ | 	return &SeriesResponse{ | ||||||
| 		Series: []*Series{ | 		Series: []*Series{ | ||||||
|  | @ -483,5 +482,5 @@ func (f *FakeClient) GetSeries(ctx context.Context, profileTypeID, labelSelector | ||||||
| 		}, | 		}, | ||||||
| 		Units: "count", | 		Units: "count", | ||||||
| 		Label: "test", | 		Label: "test", | ||||||
| 	}, http.Header{}, nil | 	}, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -65,7 +65,7 @@ func (d *ParcaDatasource) callProfileTypes(ctx context.Context, req *backend.Cal | ||||||
| 		span.SetStatus(codes.Error, err.Error()) | 		span.SetStatus(codes.Error, err.Error()) | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	err = sender.Send(&backend.CallResourceResponse{Body: data, Headers: res.Header(), Status: 200}) | 	err = sender.Send(&backend.CallResourceResponse{Body: data, Status: 200}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		ctxLogger.Error("Failed to send data to Parca", "error", err, "function", logEntrypoint()) | 		ctxLogger.Error("Failed to send data to Parca", "error", err, "function", logEntrypoint()) | ||||||
| 		span.RecordError(err) | 		span.RecordError(err) | ||||||
|  | @ -98,7 +98,7 @@ func (d *ParcaDatasource) callLabelNames(ctx context.Context, req *backend.CallR | ||||||
| 		span.SetStatus(codes.Error, err.Error()) | 		span.SetStatus(codes.Error, err.Error()) | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	err = sender.Send(&backend.CallResourceResponse{Body: data, Headers: res.Header(), Status: 200}) | 	err = sender.Send(&backend.CallResourceResponse{Body: data, Status: 200}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		ctxLogger.Error("Failed to send data to Parca", "error", err, "function", logEntrypoint()) | 		ctxLogger.Error("Failed to send data to Parca", "error", err, "function", logEntrypoint()) | ||||||
| 		span.RecordError(err) | 		span.RecordError(err) | ||||||
|  | @ -142,7 +142,7 @@ func (d *ParcaDatasource) callLabelValues(ctx context.Context, req *backend.Call | ||||||
| 		span.SetStatus(codes.Error, err.Error()) | 		span.SetStatus(codes.Error, err.Error()) | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	err = sender.Send(&backend.CallResourceResponse{Body: data, Headers: res.Header(), Status: 200}) | 	err = sender.Send(&backend.CallResourceResponse{Body: data, Status: 200}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		ctxLogger.Error("Failed to send data to Parca", "error", err, "function", logEntrypoint()) | 		ctxLogger.Error("Failed to send data to Parca", "error", err, "function", logEntrypoint()) | ||||||
| 		span.RecordError(err) | 		span.RecordError(err) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue