mirror of
https://github.com/grafana/grafana.git
synced 2024-11-24 09:50:29 -06:00
AzureMonitor: Set Logs portal URL from resource URI (#60583)
Set URL based off of resource URI
This commit is contained in:
parent
16c6f223ba
commit
f3f043e097
@ -202,8 +202,7 @@ func (e *AzureLogAnalyticsDatasource) executeQuery(ctx context.Context, logger l
|
|||||||
|
|
||||||
err = setAdditionalFrameMeta(frame,
|
err = setAdditionalFrameMeta(frame,
|
||||||
query.Params.Get("query"),
|
query.Params.Get("query"),
|
||||||
model.Get("subscriptionId").MustString(),
|
model.Get("azureLogAnalytics").Get("resource").MustString())
|
||||||
model.Get("azureLogAnalytics").Get("workspace").MustString())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
frame.AppendNotices(data.Notice{Severity: data.NoticeSeverityWarning, Text: "could not add custom metadata: " + err.Error()})
|
frame.AppendNotices(data.Notice{Severity: data.NoticeSeverityWarning, Text: "could not add custom metadata: " + err.Error()})
|
||||||
logger.Warn("failed to add custom metadata to azure log analytics response", err)
|
logger.Warn("failed to add custom metadata to azure log analytics response", err)
|
||||||
@ -317,12 +316,11 @@ func (e *AzureLogAnalyticsDatasource) unmarshalResponse(logger log.Logger, res *
|
|||||||
// LogAnalyticsMeta is a type for the a Frame's Meta's Custom property.
|
// LogAnalyticsMeta is a type for the a Frame's Meta's Custom property.
|
||||||
type LogAnalyticsMeta struct {
|
type LogAnalyticsMeta struct {
|
||||||
ColumnTypes []string `json:"azureColumnTypes"`
|
ColumnTypes []string `json:"azureColumnTypes"`
|
||||||
Subscription string `json:"subscription"`
|
|
||||||
Workspace string `json:"workspace"`
|
|
||||||
EncodedQuery []byte `json:"encodedQuery"` // EncodedQuery is used for deep links.
|
EncodedQuery []byte `json:"encodedQuery"` // EncodedQuery is used for deep links.
|
||||||
|
Resource string `json:"resource"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func setAdditionalFrameMeta(frame *data.Frame, query, subscriptionID, workspace string) error {
|
func setAdditionalFrameMeta(frame *data.Frame, query, resource string) error {
|
||||||
if frame.Meta == nil || frame.Meta.Custom == nil {
|
if frame.Meta == nil || frame.Meta.Custom == nil {
|
||||||
// empty response
|
// empty response
|
||||||
return nil
|
return nil
|
||||||
@ -332,8 +330,7 @@ func setAdditionalFrameMeta(frame *data.Frame, query, subscriptionID, workspace
|
|||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unexpected type found for frame's custom metadata")
|
return fmt.Errorf("unexpected type found for frame's custom metadata")
|
||||||
}
|
}
|
||||||
la.Subscription = subscriptionID
|
la.Resource = resource
|
||||||
la.Workspace = workspace
|
|
||||||
encodedQuery, err := encodeQuery(query)
|
encodedQuery, err := encodeQuery(query)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
la.EncodedQuery = encodedQuery
|
la.EncodedQuery = encodedQuery
|
||||||
|
@ -247,7 +247,7 @@ func Test_executeQueryErrorWithDifferentLogAnalyticsCreds(t *testing.T) {
|
|||||||
func Test_setAdditionalFrameMeta(t *testing.T) {
|
func Test_setAdditionalFrameMeta(t *testing.T) {
|
||||||
t.Run("it should not error with an empty response", func(t *testing.T) {
|
t.Run("it should not error with an empty response", func(t *testing.T) {
|
||||||
frame := data.NewFrame("test")
|
frame := data.NewFrame("test")
|
||||||
err := setAdditionalFrameMeta(frame, "", "", "")
|
err := setAdditionalFrameMeta(frame, "", "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -184,19 +184,12 @@ export default class AzureLogAnalyticsDatasource extends DataSourceWithBackend<
|
|||||||
|
|
||||||
private async buildDeepLink(customMeta: Record<string, any>) {
|
private async buildDeepLink(customMeta: Record<string, any>) {
|
||||||
const base64Enc = encodeURIComponent(customMeta.encodedQuery);
|
const base64Enc = encodeURIComponent(customMeta.encodedQuery);
|
||||||
const workspaceId = customMeta.workspace;
|
const resource = encodeURIComponent(customMeta.resource);
|
||||||
const subscription = customMeta.subscription;
|
|
||||||
|
|
||||||
const details = await this.getWorkspaceDetails(workspaceId);
|
|
||||||
if (!details.workspace || !details.resourceGroup) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
const url =
|
const url =
|
||||||
`${this.azurePortalUrl}/#blade/Microsoft_OperationsManagementSuite_Workspace/` +
|
`${this.azurePortalUrl}/#blade/Microsoft_OperationsManagementSuite_Workspace/` +
|
||||||
`AnalyticsBlade/initiator/AnalyticsShareLinkToQuery/isQueryEditorVisible/true/scope/` +
|
`AnalyticsBlade/initiator/AnalyticsShareLinkToQuery/isQueryEditorVisible/true/scope/` +
|
||||||
`%7B%22resources%22%3A%5B%7B%22resourceId%22%3A%22%2Fsubscriptions%2F${subscription}` +
|
`%7B%22resources%22%3A%5B%7B%22resourceId%22%3A%22${resource}` +
|
||||||
`%2Fresourcegroups%2F${details.resourceGroup}%2Fproviders%2Fmicrosoft.operationalinsights%2Fworkspaces%2F${details.workspace}` +
|
|
||||||
`%22%7D%5D%7D/query/${base64Enc}/isQueryBase64Compressed/true/timespanInIsoFormat/P1D`;
|
`%22%7D%5D%7D/query/${base64Enc}/isQueryBase64Compressed/true/timespanInIsoFormat/P1D`;
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user