Cloud Monitoring: Use new annotation API (#49026)
* remove angular code * format annotation on backend * format time with time type instead of string * update annotation query tests * update get alignment data function * update annotation query editor * add annotation query editor test * update struct * add tests * remove extracted function * remove non-null assertion * remove stray commented out console.log * fix jest haste map warning * add alignment period * add AnnotationMetricQuery type
This commit is contained in:
@@ -4,11 +4,19 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
)
|
||||
|
||||
type annotationEvent struct {
|
||||
Title string
|
||||
Time time.Time
|
||||
Tags string
|
||||
Text string
|
||||
}
|
||||
|
||||
func (s *Service) executeAnnotationQuery(ctx context.Context, req *backend.QueryDataRequest, dsInfo datasourceInfo) (
|
||||
*backend.QueryDataResponse, error) {
|
||||
resp := backend.NewQueryDataResponse()
|
||||
@@ -24,8 +32,10 @@ func (s *Service) executeAnnotationQuery(ctx context.Context, req *backend.Query
|
||||
}
|
||||
|
||||
mq := struct {
|
||||
Title string `json:"title"`
|
||||
Text string `json:"text"`
|
||||
MetricQuery struct {
|
||||
Title string `json:"title"`
|
||||
Text string `json:"text"`
|
||||
} `json:"metricQuery"`
|
||||
}{}
|
||||
|
||||
firstQuery := req.Queries[0]
|
||||
@@ -33,32 +43,23 @@ func (s *Service) executeAnnotationQuery(ctx context.Context, req *backend.Query
|
||||
if err != nil {
|
||||
return resp, nil
|
||||
}
|
||||
err = queries[0].parseToAnnotations(queryRes, dr, mq.Title, mq.Text)
|
||||
err = queries[0].parseToAnnotations(queryRes, dr, mq.MetricQuery.Title, mq.MetricQuery.Text)
|
||||
resp.Responses[firstQuery.RefID] = *queryRes
|
||||
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (timeSeriesQuery cloudMonitoringTimeSeriesQuery) transformAnnotationToFrame(annotations []map[string]string, result *backend.DataResponse) {
|
||||
frames := data.Frames{}
|
||||
func (timeSeriesQuery cloudMonitoringTimeSeriesQuery) transformAnnotationToFrame(annotations []*annotationEvent, result *backend.DataResponse) {
|
||||
frame := data.NewFrame(timeSeriesQuery.RefID,
|
||||
data.NewField("time", nil, []time.Time{}),
|
||||
data.NewField("title", nil, []string{}),
|
||||
data.NewField("tags", nil, []string{}),
|
||||
data.NewField("text", nil, []string{}),
|
||||
)
|
||||
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)
|
||||
frame.AppendRow(a.Time, a.Title, a.Tags, a.Text)
|
||||
}
|
||||
result.Frames = frames
|
||||
result.Frames = append(result.Frames, frame)
|
||||
slog.Info("anno", "len", len(annotations))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user