diff --git a/go.mod b/go.mod index bdb2dba2c23..fe0585e63da 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/gorilla/websocket v1.4.1 github.com/gosimple/slug v1.4.2 github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4 - github.com/grafana/grafana-plugin-sdk-go v0.67.0 + github.com/grafana/grafana-plugin-sdk-go v0.70.0 github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd github.com/hashicorp/go-plugin v1.2.2 github.com/hashicorp/go-version v1.1.0 diff --git a/go.sum b/go.sum index 2b11568e928..7da750ff1a7 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,8 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/apache/arrow/go/arrow v0.0.0-20200403134915-89ce1cadb678 h1:R72+9UXiP7TnpTAdznM1okjzyqb3bzopSA7HCP7p3gM= -github.com/apache/arrow/go/arrow v0.0.0-20200403134915-89ce1cadb678/go.mod h1:QNYViu/X0HXDHw7m3KXzWSVXIbfUvJqBFe6Gj8/pYA0= +github.com/apache/arrow/go/arrow v0.0.0-20200629181129-68b1273cbbf7 h1:dgL2mSOuj63SXOyojjWKq2ni3FQpQ+KrLKD7Pbq6t/4= +github.com/apache/arrow/go/arrow v0.0.0-20200629181129-68b1273cbbf7/go.mod h1:QNYViu/X0HXDHw7m3KXzWSVXIbfUvJqBFe6Gj8/pYA0= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/aws/aws-sdk-go v1.29.20 h1:vAHJhARpdbdeJstTVaugeHgvVj5lBnfz3blbbD24gfo= github.com/aws/aws-sdk-go v1.29.20/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg= @@ -148,8 +148,8 @@ github.com/gosimple/slug v1.4.2 h1:jDmprx3q/9Lfk4FkGZtvzDQ9Cj9eAmsjzeQGp24PeiQ= github.com/gosimple/slug v1.4.2/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIorhxAf0= github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4 h1:SPdxCL9BChFTlyi0Khv64vdCW4TMna8+sxL7+Chx+Ag= github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4/go.mod h1:nc0XxBzjeGcrMltCDw269LoWF9S8ibhgxolCdA1R8To= -github.com/grafana/grafana-plugin-sdk-go v0.67.0 h1:2kvI9kROmp/pXRrDQSEvcpR7Zonle7HjXgOdH70P2bw= -github.com/grafana/grafana-plugin-sdk-go v0.67.0/go.mod h1:w855JyiC5PDP3naWUJP0h/vY8RlzlE4+4fodyoXph+4= +github.com/grafana/grafana-plugin-sdk-go v0.70.0 h1:tbwf0KMp8QEQQYF3bDBOOv/npegD6YP8T90OWbLr7n4= +github.com/grafana/grafana-plugin-sdk-go v0.70.0/go.mod h1:NvxLzGkVhnoBKwzkst6CFfpMFKwAdIUZ1q8ssuLeF60= github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 h1:0IKlLyQ3Hs9nDaiK5cSHAGmcQEIC8l2Ts1u6x5Dfrqg= github.com/grpc-ecosystem/go-grpc-middleware v1.2.0/go.mod h1:mJzapYve32yjrKlk9GbyCZHuPgZsrbyIbyKhSzOpg6s= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= @@ -216,6 +216,7 @@ github.com/linkedin/goavro/v2 v2.9.7 h1:Vd++Rb/RKcmNJjM0HP/JJFMEWa21eUBVKPYlKehO github.com/linkedin/goavro/v2 v2.9.7/go.mod h1:UgQUb2N/pmueQYH9bfqFioWxzYCZXSfF8Jw03O5sjqA= github.com/lunny/log v0.0.0-20160921050905-7887c61bf0de/go.mod h1:3q8WtuPQsoRbatJuy3nvq/hRSvuBJrHHr+ybPPiNvHQ= github.com/lunny/nodb v0.0.0-20160621015157-fc1ef06ad4af/go.mod h1:Cqz6pqow14VObJ7peltM+2n3PWOz7yTrfUuGbVFkzN0= +github.com/magefile/mage v1.9.0 h1:t3AU2wNwehMCW97vuqQLtw6puppWXHO+O2MHo5a50XE= github.com/magefile/mage v1.9.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ= github.com/mattetti/filebuffer v1.0.0 h1:ixTvQ0JjBTwWbdpDZ98lLrydo7KRi8xNRIi5RFszsbY= diff --git a/pkg/tsdb/azuremonitor/azure-log-analytics-datasource.go b/pkg/tsdb/azuremonitor/azure-log-analytics-datasource.go index f6a3947aa72..8779e8ba380 100644 --- a/pkg/tsdb/azuremonitor/azure-log-analytics-datasource.go +++ b/pkg/tsdb/azuremonitor/azure-log-analytics-datasource.go @@ -162,10 +162,14 @@ func (e *AzureLogAnalyticsDatasource) executeQuery(ctx context.Context, query *A return queryResultError(err) } - setAdditionalFrameMeta(frame, + err = setAdditionalFrameMeta(frame, query.Params.Get("query"), query.Model.Get("subscriptionId").MustString(), query.Model.Get("azureLogAnalytics").Get("workspace").MustString()) + if err != nil { + frame.AppendNotices(data.Notice{Severity: data.NoticeSeverityWarning, Text: "could not add custom metadata: " + err.Error()}) + azlog.Warn("failed to add custom metadata to azure log analytics response", err) + } if query.ResultFormat == "time_series" { tsSchema := frame.TimeSeriesSchema() @@ -273,16 +277,28 @@ func (e *AzureLogAnalyticsDatasource) unmarshalResponse(res *http.Response) (Azu return data, nil } -func setAdditionalFrameMeta(frame *data.Frame, query, subscriptionID, workspace string) { +// LogAnalyticsMeta is a type for the a Frame's Meta's Custom property. +type LogAnalyticsMeta struct { + ColumnTypes []string `json:"azureColumnTypes"` + Subscription string `json:"subscription"` + Workspace string `json:"workspace"` + EncodedQuery []byte `json:"encodedQuery"` // EncodedQuery is used for deep links. +} + +func setAdditionalFrameMeta(frame *data.Frame, query, subscriptionID, workspace string) error { frame.Meta.ExecutedQueryString = query - frame.Meta.Custom["subscription"] = subscriptionID - frame.Meta.Custom["workspace"] = workspace + la, ok := frame.Meta.Custom.(*LogAnalyticsMeta) + if !ok { + return fmt.Errorf("unexpected type found for frame's custom metadata") + } + la.Subscription = subscriptionID + la.Workspace = workspace encodedQuery, err := encodeQuery(query) if err == nil { - frame.Meta.Custom["encodedQuery"] = encodedQuery - return + la.EncodedQuery = encodedQuery + return nil } - azlog.Error("failed to encode the query into the encodedQuery property") + return fmt.Errorf("failed to encode the query into the encodedQuery property") } // encodeQuery encodes the query in gzip so the frontend can build links. diff --git a/pkg/tsdb/azuremonitor/azure-log-analytics-table-frame.go b/pkg/tsdb/azuremonitor/azure-log-analytics-table-frame.go index 54997424cb6..27adffcb226 100644 --- a/pkg/tsdb/azuremonitor/azure-log-analytics-table-frame.go +++ b/pkg/tsdb/azuremonitor/azure-log-analytics-table-frame.go @@ -52,7 +52,7 @@ func converterFrameForTable(t *AzureLogAnalyticsTable) (*data.FrameInputConverte } fic.Frame.Meta = &data.FrameMeta{ - Custom: map[string]interface{}{"azureColumnTypes": colTypes}, + Custom: &LogAnalyticsMeta{ColumnTypes: colTypes}, } return fic, nil diff --git a/pkg/tsdb/azuremonitor/azure-log-analytics-table-frame_test.go b/pkg/tsdb/azuremonitor/azure-log-analytics-table-frame_test.go index 885b99db30a..a9e624c9adb 100644 --- a/pkg/tsdb/azuremonitor/azure-log-analytics-table-frame_test.go +++ b/pkg/tsdb/azuremonitor/azure-log-analytics-table-frame_test.go @@ -41,7 +41,7 @@ func TestLogTableToFrame(t *testing.T) { }), ) frame.Meta = &data.FrameMeta{ - Custom: map[string]interface{}{"azureColumnTypes": []string{"datetime", "string", "real"}}, + Custom: &LogAnalyticsMeta{ColumnTypes: []string{"datetime", "string", "real"}}, } return frame }, @@ -91,7 +91,7 @@ func TestLogTableToFrame(t *testing.T) { }), ) frame.Meta = &data.FrameMeta{ - Custom: map[string]interface{}{"azureColumnTypes": []string{"string", "string", "string", + Custom: &LogAnalyticsMeta{ColumnTypes: []string{"string", "string", "string", "string", "string", "real", "real", "int", "real", "datetime"}}, } return frame @@ -113,7 +113,7 @@ func TestLogTableToFrame(t *testing.T) { data.NewField("XTimeSpan", nil, []*string{pointer.String("00:00:00.0000001")}), ) frame.Meta = &data.FrameMeta{ - Custom: map[string]interface{}{"azureColumnTypes": []string{"bool", "string", "datetime", + Custom: &LogAnalyticsMeta{ColumnTypes: []string{"bool", "string", "datetime", "dynamic", "guid", "int", "long", "real", "timespan"}}, } return frame