AzureMonitor: Fix Log Analytics portal links (#65482)
* Fix and update Log Analytics portal links - Build portal URL in backend - Correctly set multiple resource value - Move AddConfigLinks util function - Add necessary types - Remove unused functions * Fix lint issue * Remove unused cache variable
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-azure-sdk-go/azsettings"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
@@ -203,13 +202,13 @@ func (e *AzureResourceGraphDatasource) executeQuery(ctx context.Context, logger
|
||||
return dataResponse
|
||||
}
|
||||
|
||||
azurePortalUrl, err := GetAzurePortalUrl(dsInfo.Cloud)
|
||||
azurePortalUrl, err := loganalytics.GetAzurePortalUrl(dsInfo.Cloud)
|
||||
if err != nil {
|
||||
return dataResponseErrorWithExecuted(err)
|
||||
}
|
||||
|
||||
url := azurePortalUrl + "/#blade/HubsExtension/ArgQueryBlade/query/" + url.PathEscape(query.InterpolatedQuery)
|
||||
frameWithLink := AddConfigLinks(*frame, url)
|
||||
frameWithLink := loganalytics.AddConfigLinks(*frame, url)
|
||||
if frameWithLink.Meta == nil {
|
||||
frameWithLink.Meta = &data.FrameMeta{}
|
||||
}
|
||||
@@ -219,21 +218,6 @@ func (e *AzureResourceGraphDatasource) executeQuery(ctx context.Context, logger
|
||||
return dataResponse
|
||||
}
|
||||
|
||||
func AddConfigLinks(frame data.Frame, dl string) data.Frame {
|
||||
for i := range frame.Fields {
|
||||
if frame.Fields[i].Config == nil {
|
||||
frame.Fields[i].Config = &data.FieldConfig{}
|
||||
}
|
||||
deepLink := data.DataLink{
|
||||
Title: "View in Azure Portal",
|
||||
TargetBlank: true,
|
||||
URL: dl,
|
||||
}
|
||||
frame.Fields[i].Config.Links = append(frame.Fields[i].Config.Links, deepLink)
|
||||
}
|
||||
return frame
|
||||
}
|
||||
|
||||
func (e *AzureResourceGraphDatasource) createRequest(ctx context.Context, logger log.Logger, reqBody []byte, url string) (*http.Request, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewBuffer(reqBody))
|
||||
if err != nil {
|
||||
@@ -273,16 +257,3 @@ func (e *AzureResourceGraphDatasource) unmarshalResponse(logger log.Logger, res
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func GetAzurePortalUrl(azureCloud string) (string, error) {
|
||||
switch azureCloud {
|
||||
case azsettings.AzurePublic:
|
||||
return "https://portal.azure.com", nil
|
||||
case azsettings.AzureChina:
|
||||
return "https://portal.azure.cn", nil
|
||||
case azsettings.AzureUSGovernment:
|
||||
return "https://portal.azure.us", nil
|
||||
default:
|
||||
return "", fmt.Errorf("the cloud is not supported")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/tsdb/azuremonitor/loganalytics"
|
||||
"github.com/grafana/grafana/pkg/tsdb/azuremonitor/types"
|
||||
)
|
||||
|
||||
@@ -124,7 +125,7 @@ func TestAddConfigData(t *testing.T) {
|
||||
frame := data.Frame{
|
||||
Fields: []*data.Field{&field},
|
||||
}
|
||||
frameWithLink := AddConfigLinks(frame, "http://ds")
|
||||
frameWithLink := loganalytics.AddConfigLinks(frame, "http://ds")
|
||||
expectedFrameWithLink := data.Frame{
|
||||
Fields: []*data.Field{
|
||||
{
|
||||
@@ -148,7 +149,7 @@ func TestGetAzurePortalUrl(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, cloud := range clouds {
|
||||
azurePortalUrl, err := GetAzurePortalUrl(cloud)
|
||||
azurePortalUrl, err := loganalytics.GetAzurePortalUrl(cloud)
|
||||
if err != nil {
|
||||
t.Errorf("The cloud not supported")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user