mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 07:35:45 -06:00
* Separate Tracer interface to TracerService and Tracer * Fix lint * Fix:Make it possible to start spans for both opentracing and opentelemetry in ds proxy * Add span methods, use span interface for rest of tracing * Fix logs in tracing * Fix tests that are related to tracing * Fix resourcepermissions test * Fix some tests * Fix more tests * Add TracingService to wire cli runner * Remove GlobalTracer from bus * Renaming test function * Remove GlobalTracer from TSDB * Replace GlobalTracer in api * Adjust tests to the InitializeForTests func * Remove GlobalTracer from services * Remove GlobalTracer * Remove bus.NewTest * Remove Tracer interface * Add InitializeForBus * Simplify tests * Clean up tests * Rename TracerService to Tracer * Update pkg/middleware/request_tracing.go Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> * Initialize tracer before passing it to SQLStore initialization in commands * Remove tests for opentracing * Set span attributes correctly, remove unnecessary trace initiliazation form test * Add tracer instance to newSQLStore * Fix changes due to rebase * Add modified tracing middleware test * Fix opentracing implementation tags Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
102 lines
2.6 KiB
Go
102 lines
2.6 KiB
Go
package cloudmonitoring
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"strings"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
"github.com/grafana/grafana-plugin-sdk-go/data"
|
|
)
|
|
|
|
func (s *Service) executeAnnotationQuery(ctx context.Context, req *backend.QueryDataRequest, dsInfo datasourceInfo) (
|
|
*backend.QueryDataResponse, error) {
|
|
resp := backend.NewQueryDataResponse()
|
|
|
|
queries, err := s.buildQueryExecutors(req)
|
|
if err != nil {
|
|
return resp, err
|
|
}
|
|
|
|
queryRes, dr, _, err := queries[0].run(ctx, req, s, dsInfo, s.tracer)
|
|
if err != nil {
|
|
return resp, err
|
|
}
|
|
|
|
mq := struct {
|
|
Title string `json:"title"`
|
|
Text string `json:"text"`
|
|
}{}
|
|
|
|
firstQuery := req.Queries[0]
|
|
err = json.Unmarshal(firstQuery.JSON, &mq)
|
|
if err != nil {
|
|
return resp, nil
|
|
}
|
|
err = queries[0].parseToAnnotations(queryRes, dr, mq.Title, mq.Text)
|
|
resp.Responses[firstQuery.RefID] = *queryRes
|
|
|
|
return resp, err
|
|
}
|
|
|
|
func (timeSeriesQuery cloudMonitoringTimeSeriesQuery) transformAnnotationToFrame(annotations []map[string]string, result *backend.DataResponse) {
|
|
frames := data.Frames{}
|
|
for _, a := range annotations {
|
|
frame := &data.Frame{
|
|
RefID: timeSeriesQuery.getRefID(),
|
|
Fields: []*data.Field{
|
|
data.NewField("time", nil, a["time"]),
|
|
data.NewField("title", nil, a["title"]),
|
|
data.NewField("tags", nil, a["tags"]),
|
|
data.NewField("text", nil, a["text"]),
|
|
},
|
|
Meta: &data.FrameMeta{
|
|
Custom: map[string]interface{}{
|
|
"rowCount": len(a),
|
|
},
|
|
},
|
|
}
|
|
frames = append(frames, frame)
|
|
}
|
|
result.Frames = frames
|
|
slog.Info("anno", "len", len(annotations))
|
|
}
|
|
|
|
func formatAnnotationText(annotationText string, pointValue string, metricType string, metricLabels map[string]string, resourceLabels map[string]string) string {
|
|
result := legendKeyFormat.ReplaceAllFunc([]byte(annotationText), func(in []byte) []byte {
|
|
metaPartName := strings.Replace(string(in), "{{", "", 1)
|
|
metaPartName = strings.Replace(metaPartName, "}}", "", 1)
|
|
metaPartName = strings.TrimSpace(metaPartName)
|
|
|
|
if metaPartName == "metric.type" {
|
|
return []byte(metricType)
|
|
}
|
|
|
|
metricPart := replaceWithMetricPart(metaPartName, metricType)
|
|
|
|
if metricPart != nil {
|
|
return metricPart
|
|
}
|
|
|
|
if metaPartName == "metric.value" {
|
|
return []byte(pointValue)
|
|
}
|
|
|
|
metaPartName = strings.Replace(metaPartName, "metric.label.", "", 1)
|
|
|
|
if val, exists := metricLabels[metaPartName]; exists {
|
|
return []byte(val)
|
|
}
|
|
|
|
metaPartName = strings.Replace(metaPartName, "resource.label.", "", 1)
|
|
|
|
if val, exists := resourceLabels[metaPartName]; exists {
|
|
return []byte(val)
|
|
}
|
|
|
|
return in
|
|
})
|
|
|
|
return string(result)
|
|
}
|