Chore: Update cloud monitoring and Azure data sources to support contextual logs (#57844)
* update cloud monitoring to use log from context * update azure monitor to use contextual logger
This commit is contained in:
@@ -14,12 +14,16 @@ import (
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/tsdb/azuremonitor/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/tsdb/azuremonitor/types"
|
||||
)
|
||||
|
||||
var logger = log.New("test")
|
||||
|
||||
func TestBuildingAzureResourceGraphQueries(t *testing.T) {
|
||||
datasource := &AzureResourceGraphDatasource{}
|
||||
fromStart := time.Date(2018, 3, 15, 13, 0, 0, 0, time.UTC).In(time.Local)
|
||||
@@ -70,7 +74,7 @@ func TestBuildingAzureResourceGraphQueries(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
queries, err := datasource.buildQueries(tt.queryModel, types.DatasourceInfo{})
|
||||
queries, err := datasource.buildQueries(logger, tt.queryModel, types.DatasourceInfo{})
|
||||
tt.Err(t, err)
|
||||
if diff := cmp.Diff(tt.azureResourceGraphQueries, queries, cmpopts.IgnoreUnexported(simplejson.Json{})); diff != "" {
|
||||
t.Errorf("Result mismatch (-want +got):\n%s", diff)
|
||||
@@ -82,7 +86,6 @@ func TestBuildingAzureResourceGraphQueries(t *testing.T) {
|
||||
func TestAzureResourceGraphCreateRequest(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
url := "http://ds"
|
||||
dsInfo := types.DatasourceInfo{}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -104,7 +107,7 @@ func TestAzureResourceGraphCreateRequest(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ds := AzureResourceGraphDatasource{}
|
||||
req, err := ds.createRequest(ctx, dsInfo, []byte{}, url)
|
||||
req, err := ds.createRequest(ctx, logger, []byte{}, url)
|
||||
tt.Err(t, err)
|
||||
if req.URL.String() != tt.expectedURL {
|
||||
t.Errorf("Expecting %s, got %s", tt.expectedURL, req.URL.String())
|
||||
@@ -157,7 +160,7 @@ func TestGetAzurePortalUrl(t *testing.T) {
|
||||
|
||||
func TestUnmarshalResponse400(t *testing.T) {
|
||||
datasource := &AzureResourceGraphDatasource{}
|
||||
res, err := datasource.unmarshalResponse(&http.Response{
|
||||
res, err := datasource.unmarshalResponse(logger, &http.Response{
|
||||
StatusCode: 400,
|
||||
Status: "400 Bad Request",
|
||||
Body: io.NopCloser(strings.NewReader(("Azure Error Message"))),
|
||||
@@ -171,7 +174,7 @@ func TestUnmarshalResponse400(t *testing.T) {
|
||||
|
||||
func TestUnmarshalResponse200Invalid(t *testing.T) {
|
||||
datasource := &AzureResourceGraphDatasource{}
|
||||
res, err := datasource.unmarshalResponse(&http.Response{
|
||||
res, err := datasource.unmarshalResponse(logger, &http.Response{
|
||||
StatusCode: 200,
|
||||
Status: "OK",
|
||||
Body: io.NopCloser(strings.NewReader(("Azure Data"))),
|
||||
@@ -186,7 +189,7 @@ func TestUnmarshalResponse200Invalid(t *testing.T) {
|
||||
|
||||
func TestUnmarshalResponse200(t *testing.T) {
|
||||
datasource := &AzureResourceGraphDatasource{}
|
||||
res, err2 := datasource.unmarshalResponse(&http.Response{
|
||||
res, err2 := datasource.unmarshalResponse(logger, &http.Response{
|
||||
StatusCode: 200,
|
||||
Status: "OK",
|
||||
Body: io.NopCloser(strings.NewReader("{}")),
|
||||
|
||||
Reference in New Issue
Block a user