-
Notifications
You must be signed in to change notification settings - Fork 267
add purge support for log analytics #6566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d74e4b4
purge log anlaytics
hemarina 2aaac59
Merge branch 'main' of https://github.com/Azure/azure-dev into fix-5080
hemarina fe705e6
go mod tidy
hemarina b5ad075
Update cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go
hemarina 8c9f9cd
Update cli/azd/go.mod
hemarina 96fdb13
add tests
hemarina e319154
Merge branch 'fix-5080' of https://github.com/hemarina/azure-dev into…
hemarina 9a1cd80
go mod tidy
hemarina dd1aac6
add comment
hemarina 5d19943
add comment
hemarina 3be144e
address feedback
hemarina 3fc70f7
add comment
hemarina 1eaf88d
golangci-lint
hemarina aaaa2e7
rerun recording
hemarina e0ae55e
re run recording for containerapp
hemarina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package azapi | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" | ||
| "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/operationalinsights/armoperationalinsights/v2" | ||
| ) | ||
|
|
||
| type AzCliLogAnalyticsWorkspace struct { | ||
| Id string `json:"id"` | ||
| Name string `json:"name"` | ||
| } | ||
|
|
||
| func (cli *AzureClient) GetLogAnalyticsWorkspace( | ||
| ctx context.Context, | ||
| subscriptionId string, | ||
| resourceGroupName string, | ||
| workspaceName string, | ||
| ) (*AzCliLogAnalyticsWorkspace, error) { | ||
| workspacesClient, err := cli.createLogAnalyticsWorkspacesClient(ctx, subscriptionId) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| workspace, err := workspacesClient.Get(ctx, resourceGroupName, workspaceName, nil) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed getting log analytics workspace: %w", err) | ||
| } | ||
|
|
||
| return &AzCliLogAnalyticsWorkspace{ | ||
| Id: *workspace.ID, | ||
| Name: *workspace.Name, | ||
| }, nil | ||
| } | ||
|
|
||
| func (cli *AzureClient) PurgeLogAnalyticsWorkspace( | ||
| ctx context.Context, | ||
| subscriptionId string, | ||
| resourceGroupName string, | ||
| workspaceName string, | ||
| ) error { | ||
| workspacesClient, err := cli.createLogAnalyticsWorkspacesClient(ctx, subscriptionId) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| deleteOpts := &armoperationalinsights.WorkspacesClientBeginDeleteOptions{ | ||
| Force: to.Ptr(true), | ||
| } | ||
|
|
||
| // https://learn.microsoft.com/rest/api/loganalytics/workspaces/delete?view=rest-loganalytics-2025-07-01&tabs=HTTP | ||
| // Purging a workspace is done by setting the Force parameter to true when deleting the workspace | ||
| poller, err := workspacesClient.BeginDelete(ctx, resourceGroupName, workspaceName, deleteOpts) | ||
hemarina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| return fmt.Errorf("starting purging log analytics workspace: %w", err) | ||
| } | ||
|
|
||
| _, err = poller.PollUntilDone(ctx, nil) | ||
| if err != nil { | ||
| return fmt.Errorf("purging log analytics workspace: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (cli *AzureClient) createLogAnalyticsWorkspacesClient( | ||
| ctx context.Context, | ||
| subscriptionId string, | ||
| ) (*armoperationalinsights.WorkspacesClient, error) { | ||
| credential, err := cli.credentialProvider.CredentialForSubscription(ctx, subscriptionId) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| client, err := armoperationalinsights.NewWorkspacesClient(subscriptionId, credential, cli.armClientOptions) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("creating log analytics workspaces client: %w", err) | ||
| } | ||
|
|
||
| return client, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.