-
Notifications
You must be signed in to change notification settings - Fork 29
Migrate self-hosted grafana to azure managed grafana #6304
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
Open
haruna99
wants to merge
138
commits into
main
Choose a base branch
from
haruna/managed-grafana-new
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
138 commits
Select commit
Hold shift + click to select a range
cdc0c92
provision Azure Managed Grafana workspace
fb7997d
put variables in the right position
e13fb60
remove conditional statement
03b5d4f
update windows to use 1es-windows-2022
4a5ed6d
remove bicep installation task
ec7b956
remove parameters that are not needed
28e0eda
changed parameters file format for bicep
a5805d6
changed parameters file format for bicep
5424b0c
remove role assignment from bicep
e0004fc
remove role assignment from bicep
0ef9267
changed parameters file format for bicep
0382325
changed parameters file format for bicep
e8a9e30
add task to install amg extension
aa6018d
remove allow-preview-versions flag
ac429bd
assign grafana admin role to .net eng services
5683982
assign grafana admin role to .net eng services
340831d
assign grafana admin role to .net eng services
c76bcc4
remove grafana admin role assignment
eed1aed
add release job type
90cdefc
remove release job type
f533797
provision azure managed grafana workspace
a074e78
fix bicep file path
7fc2c34
add provsion grafana stage to the deployment
2273352
Merge branch 'main' into haruna/managed-grafana-new
haruna99 b5ea9ca
add deploy azure managed grafana script
ccc335f
Merge updates for Azure Managed Grafana provisioning pipeline
6ff2dba
remove test pipeline
8106d3b
delete deploy-grafana.ps1 file
7e71347
add grafana bicep validation task to the pr jobs
2c39d25
add grafana bicep validation to the build stage
4d2041c
remove unused GrafanaKeyVault parameter
758a85c
remove unused GrafanaVariableGroup parameter
71c3d73
add skuName variable
cf44564
remove unused SkipGrafanaProvisioning parameter
0e9664d
reduce maximum attempts to 5 for grafana deployment
4d387fe
remove output variables since there is no downstream usage
ed34f93
make the dotnet eng services group the grafana admin
85b7227
test grafana
669da0d
test grafana
9b2a2e5
test grafana
bfa2882
remove group grafana admin assignment
bc29c7b
add user assigned managed identity
0351d84
add user assigned managed identity
363a9af
add key vault for grafana
f3e8036
change resource group name
6fae23b
change resource group validation script
170a6c2
change service connection
8a6a3a4
change service connection
a13a12d
change service connection to use nethelix sc
330b56f
grant the managed identity permissions to the keyvault
b5306a4
give the .net eng services group grafana admin permissions
d99edad
change the service connection to Dotnet Engineering services
48cdf59
change grafana keyvault name
c10a8d8
add application gateway
a216a49
add application gateway
9ac0129
rectify image used for app gateway
2b36a31
rectify image used for app gateway
b988c49
remove unused service connection id and rectify subscription
ac504aa
Enable HTTPS on Application Gateway
5445e58
Enable HTTPS on Application Gateway
b106927
remove incorrect operator
17c1ba7
remove incorrect operator
acc362b
remove incorrect operator
11618a7
fix script path
916faf5
grant the grafana MI Key Vault Certificates Officer role
c8eec92
grant pipeline service principal Key Vault Certificates Officer role
a71a2cc
Grant Application Gateway Access to Key Vault
6d98a29
Fix 502 error: Accept 401 status from Grafana health probe
c1f94c3
publish grafana dashboard
59540e6
add token creation to publish grafana stage
0a79b46
grant service principal grafana admin role
7d95e70
grant service principal key vault officer role
0e2b751
Grant pipeline SP Key Vault Secrets Officer role in Grafana provision…
25be23e
Add Key Vault permission verification and retry logic for RBAC propag…
ab8601e
Pass Azure Pipelines credentials to MSBuild SDK for Key Vault authent…
d40d857
add service connection ID
ca72eb5
add service connection client ID
4b97270
remove undefined ServiceConnectionId
7f3fda8
import secrets from dotnet-grafana-secrets.yaml
9f6d58d
remove dnceng-amg-int-kv.yaml file
81f4ed5
remove notification alerts and synchronize secrets
381b936
fix key vault access propagation
c617b3a
fix keyvault secret access
6f68e64
grant MI monitoring reader permission to subscriptions
5ce1be5
grant MI monitoring reader permission to subscriptions in the pipeline
5d05dbe
fix grafana notification contact points
b30cf22
azure managed grafana alert rules
69a2709
add quota alerts
d09e4e6
import secret to staging and prod KV
7b74036
remove unused output variables
0fdc086
remove unused output variables in azure managed grafana bicep
e5048af
remove EnableCustomDomain variable from deploy-managed-grafana.yml
edab753
remove unnecessary comments
b73f5f6
remove unnecessary comments
e24c9df
remove unnecessary comments
a0fd967
change token lifespan to 30 days
3dd87e9
remove unnecessary comments
2b65635
remove unused contact point
d5582a7
fix duplication of contact points
070fbeb
include dashboard for homepage
3f10420
remove plugin version
0517896
remove app gateway logic
98f709a
Migrate alert rules to Azure Managed Grafana unified alerting format
f091797
grant grafa MI access to engineeringdata
e4a35f5
grant grafa MI access to engineeringdata
9ad1f73
grant grafa MI access to engineeringdata
ddcce3e
grant grafana MI access to engineeringdata
6e3def1
remove grafana MI access to engineeringdata
e9d06c9
fix data source for dashboard
88c34a1
update grafana dashboards
5606316
set homepage preference
c223f45
fix dashboard alert annotations
af36144
add grafana keyvault manifest file
83d0b66
add grafana annotation settings for infinity datasource
2ca58ac
show inactive alerts
7d0a9cd
set alert rule timeframe
fd13b74
fix alerting rules folder directory
f25346e
refactor grafana publishing to use only one stage
3e02792
refactor grafana publishing to use only one stage
1b3005e
add managed grafana to the dotnet-dnceng-ci pipeline
44bc88a
add managed grafana to the dotnet-dnceng-ci pipeline
98aa83b
remove self hosted grafana dashboard publishing
c087a93
fix grafana dashboard publishing error
dd901b2
fix error when adding ANG to dotnet-dnceng-ci pipeline
6eaa430
remove test pipeline
89c3cf8
fix deploy-managed-grafana.ml filepath
382350c
include serviceConnectionName variable
5e64cdb
Allow anonymous access to alert webhook endpoint for Grafana
840b1e3
remove AllowAnonymous from alertHookController
2064f8a
Merge remote-tracking branch 'origin/main' into haruna/managed-grafan…
75f2091
delete azure-pipelines-managed-grafana pipeline
f406766
remove unnecessary comment
eff6b13
Merge branch 'main' into haruna/managed-grafana-new
haruna99 93896b0
fix service connection naming
cc08ecf
Merge branch 'haruna/managed-grafana-new' of https://github.com/dotne…
554a3e2
remove Validation of the Grafana Bicep Template from the PR stage
b42bc65
add azure managed grafana api key to secret manager
708dd92
remove unused files
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| storageLocation: | ||
| type: azure-key-vault | ||
| parameters: | ||
| subscription: a4fc5514-21a9-4296-bfaf-5c7ee7fa35d1 | ||
| name: dnceng-amg-int-kv | ||
|
|
||
| secrets: | ||
| # API token for DotNet Status website | ||
| dotnet-build-bot-dotnet-eng-status-token: | ||
| type: text | ||
| parameters: | ||
| description: API token from https://dotneteng-status-staging.azurewebsites.net/ - Generated using dotnet-build-bot account | ||
|
|
||
| # Authorization header for Deployment Annotations datasource | ||
| dotneteng-status-auth-header: | ||
| type: text | ||
| parameters: | ||
| description: "Bearer token for status API - Format: Bearer <dotnet-build-bot-dotnet-eng-status-token>" | ||
|
|
||
| # Teams webhook URL for alert notifications | ||
| fr-bot-notifications-teams-notification-url: | ||
| type: text | ||
| parameters: | ||
| description: Teams Incoming Webhook URL - Do not rotate |
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,24 @@ | ||
| storageLocation: | ||
| type: azure-key-vault | ||
| parameters: | ||
| subscription: a4fc5514-21a9-4296-bfaf-5c7ee7fa35d1 | ||
| name: dnceng-amg-prod-kv | ||
|
|
||
| secrets: | ||
| # API token for DotNet Status website | ||
| dotnet-build-bot-dotnet-eng-status-token: | ||
| type: text | ||
| parameters: | ||
| description: API token from https://dotneteng-status.azurewebsites.net/ - Generated using dotnet-build-bot account | ||
|
|
||
| # Authorization header for Deployment Annotations datasource | ||
| dotneteng-status-auth-header: | ||
| type: text | ||
| parameters: | ||
| description: "Bearer token for status API - Format: Bearer <dotnet-build-bot-dotnet-eng-status-token>" | ||
|
|
||
| # Teams webhook URL for alert notifications | ||
| fr-bot-notifications-teams-notification-url: | ||
| type: text | ||
| parameters: | ||
| description: Teams Incoming Webhook URL - Do not rotate |
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,208 @@ | ||
| parameters: | ||
| - name: AMGServiceConnectionName | ||
| type: string | ||
| - name: AMGServiceConnectionClientId | ||
| type: string | ||
| - name: AMGServiceConnectionId | ||
| type: string | ||
| - name: AMGDeploymentEnvironment | ||
| type: string | ||
| - name: AMGGrafanaWorkspaceName | ||
| type: string | ||
| - name: AMGGrafanaKeyVault | ||
| type: string | ||
|
|
||
| stages: | ||
| - stage: DeployGrafana | ||
| displayName: 'Deploy Grafana Infrastructure and Dashboards' | ||
| pool: | ||
| name: NetCore1ESPool-Internal-NoMSI | ||
| demands: ImageOverride -equals 1es-windows-2019 | ||
| dependsOn: | ||
| - predeploy | ||
| - approval | ||
| jobs: | ||
| - template: /eng/provision-grafana.yaml@self | ||
| parameters: | ||
| DeploymentEnvironment: ${{ parameters.AMGDeploymentEnvironment }} | ||
| ServiceConnectionName: ${{ parameters.AMGServiceConnectionName }} | ||
| GrafanaResourceGroup: 'monitoring-managed' | ||
| GrafanaWorkspaceName: ${{ parameters.AMGGrafanaWorkspaceName }} | ||
| GrafanaLocation: 'westus2' | ||
| GrafanaKeyVault: ${{ parameters.AMGGrafanaKeyVault }} | ||
| - job: SetupToken | ||
| dependsOn: ProvisionGrafana | ||
| displayName: 'Setup Grafana API Token' | ||
| variables: | ||
| GrafanaEndpoint: $[ dependencies.ProvisionGrafana.outputs['ExportGrafanaInfo.GrafanaEndpoint'] ] | ||
| pool: | ||
| name: NetCore1ESPool-Internal | ||
| demands: ImageOverride -equals 1es-windows-2022 | ||
| steps: | ||
| - task: AzureCLI@2 | ||
| displayName: 'Grant Pipeline Service Principal Grafana Admin Role' | ||
| inputs: | ||
| azureSubscription: ${{ parameters.AMGServiceConnectionName }} | ||
| scriptType: 'pscore' | ||
| scriptLocation: 'inlineScript' | ||
| inlineScript: | | ||
| Write-Host "Granting pipeline service principal Grafana Admin role..." | ||
|
|
||
| $workspaceName = "${{ parameters.AMGGrafanaWorkspaceName }}" | ||
| $rgName = "monitoring-managed" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider making this a parameter as well. It can have this as the default value. Then all the tweakable variables will be up at the top in the same area. |
||
|
|
||
| # Get the current service principal object ID | ||
| $spObjectId = az account show --query "user.name" --output tsv | ||
| Write-Host "Service Principal Object ID: $spObjectId" | ||
|
|
||
| # Get the Grafana workspace resource ID | ||
| $grafanaId = az grafana show --name $workspaceName --resource-group $rgName --query "id" --output tsv | ||
| Write-Host "Grafana Workspace: $workspaceName" | ||
| Write-Host "Grafana ID: $grafanaId" | ||
|
|
||
| # Check if role assignment already exists | ||
| $existingAssignment = az role assignment list ` | ||
| --assignee $spObjectId ` | ||
| --scope $grafanaId ` | ||
| --role "Grafana Admin" ` | ||
| --query "[0].id" ` | ||
| --output tsv | ||
|
|
||
| if ($existingAssignment) { | ||
| Write-Host "✓ Pipeline service principal already has Grafana Admin role" | ||
| } else { | ||
| Write-Host "Granting Grafana Admin role..." | ||
| az role assignment create ` | ||
| --role "Grafana Admin" ` | ||
| --assignee $spObjectId ` | ||
| --scope $grafanaId ` | ||
| --output none | ||
|
|
||
| if ($LASTEXITCODE -eq 0) { | ||
| Write-Host "✓ Pipeline service principal granted Grafana Admin role" | ||
| Write-Host "⏱ Waiting 15 seconds for role assignment to propagate..." | ||
| Start-Sleep -Seconds 15 | ||
| } else { | ||
| Write-Error "Failed to grant Grafana Admin role" | ||
| exit 1 | ||
| } | ||
| } | ||
|
|
||
| - task: AzureCLI@2 | ||
| displayName: 'Create or Validate Grafana API Token' | ||
| inputs: | ||
| azureSubscription: ${{ parameters.AMGServiceConnectionName }} | ||
| scriptType: 'pscore' | ||
| scriptLocation: 'scriptPath' | ||
| scriptPath: 'eng/setup-grafana-api-token.ps1' | ||
| arguments: >- | ||
| -Environment "${{ parameters.AMGDeploymentEnvironment }}" | ||
| -KeyVaultName "${{ parameters.AMGGrafanaKeyVault }}" | ||
|
|
||
| - job: PublishDashboards | ||
| displayName: 'Publish Dashboards to Azure Managed Grafana' | ||
| dependsOn: | ||
| - ProvisionGrafana | ||
| - SetupToken | ||
| pool: | ||
| name: NetCore1ESPool-Internal | ||
| demands: ImageOverride -equals 1es-windows-2022 | ||
| variables: | ||
| GrafanaEndpoint: $[ dependencies.ProvisionGrafana.outputs['ExportGrafanaInfo.GrafanaEndpoint'] ] | ||
| System.AccessToken: $(System.AccessToken) | ||
| steps: | ||
| - task: UseDotNet@2 | ||
| displayName: 'Install Correct .NET Version' | ||
| inputs: | ||
| useGlobalJson: true | ||
|
|
||
| - script: dotnet publish --configuration Release $(Build.SourcesDirectory)\src\Monitoring\Sdk\Microsoft.DotNet.Monitoring.Sdk.csproj -f net8.0 | ||
| displayName: 'Build Monitoring SDK' | ||
|
|
||
| - task: AzureCLI@2 | ||
| displayName: 'Publish Grafana Dashboards' | ||
| inputs: | ||
| azureSubscription: ${{ parameters.AMGServiceConnectionName }} | ||
| scriptType: 'pscore' | ||
| scriptLocation: 'inlineScript' | ||
| addSpnToEnvironment: true | ||
| inlineScript: | | ||
| Write-Host "==========================================" | ||
| Write-Host "Publishing Dashboards to Azure Managed Grafana" | ||
| Write-Host "==========================================" | ||
| Write-Host "Grafana Endpoint: $(GrafanaEndpoint)" | ||
| Write-Host "Environment: ${{ parameters.AMGDeploymentEnvironment }}" | ||
| Write-Host "" | ||
|
|
||
| # Get the API token from Key Vault with retry logic for RBAC propagation | ||
| $tokenSecretName = "grafana-admin-api-key" | ||
| Write-Host "Retrieving API token from Key Vault..." | ||
|
|
||
| $apiToken = $null | ||
| $maxRetries = 5 | ||
| $retryCount = 0 | ||
| $waitSeconds = 60 | ||
|
|
||
| while (-not $apiToken -and $retryCount -lt $maxRetries) { | ||
| try { | ||
| $apiToken = az keyvault secret show --vault-name "${{ parameters.AMGGrafanaKeyVault }}" --name $tokenSecretName --query "value" --output tsv 2>&1 | ||
|
|
||
| if ($LASTEXITCODE -eq 0 -and $apiToken -and $apiToken.Trim()) { | ||
| Write-Host "✓ API token retrieved successfully from Key Vault" | ||
| break | ||
| } else { | ||
| $apiToken = $null | ||
| throw "Failed to retrieve token" | ||
| } | ||
| } catch { | ||
| $retryCount++ | ||
| if ($retryCount -lt $maxRetries) { | ||
| Write-Host "⏱ Waiting for Key Vault access (attempt $retryCount/$maxRetries, waiting $waitSeconds seconds)..." | ||
| Start-Sleep -Seconds $waitSeconds | ||
| } else { | ||
| Write-Error "Unable to retrieve API token after $maxRetries attempts ($($maxRetries * $waitSeconds) seconds total)" | ||
| Write-Error "Secret name: $tokenSecretName" | ||
| Write-Error "Key Vault: ${{ parameters.AMGGrafanaKeyVault }}" | ||
| Write-Error "" | ||
| Write-Error "Possible causes:" | ||
| Write-Error "1. RBAC permissions haven't propagated yet (can take 5-10 minutes)" | ||
| Write-Error "2. The SetupToken job failed to create the token" | ||
| Write-Error "3. The pipeline service principal doesn't have Key Vault Secrets Officer role" | ||
| Write-Error "" | ||
| exit 1 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Write-Host "" | ||
| Write-Host "Publishing dashboards using MSBuild SDK..." | ||
| Write-Host "" | ||
|
|
||
| # Publish using the same MSBuild SDK as self-hosted Grafana | ||
| dotnet build $(Build.SourcesDirectory)\src\Monitoring\Monitoring.ArcadeServices\Monitoring.ArcadeServices.proj ` | ||
| --configuration Release ` | ||
| -t:PublishGrafana ` | ||
| -p:GrafanaAccessToken=$apiToken ` | ||
| -p:GrafanaHost="$(GrafanaEndpoint)" ` | ||
| -p:GrafanaKeyVaultName="${{ parameters.AMGGrafanaKeyVault }}" ` | ||
| -p:GrafanaEnvironment="${{ parameters.AMGDeploymentEnvironment }}" ` | ||
| -p:ParametersFile=parameters.json ` | ||
| -p:ClientId="${{ parameters.AMGServiceConnectionClientId }}" ` | ||
| -p:ServiceConnectionId="${{ parameters.AMGServiceConnectionId }}" ` | ||
| -p:SystemAccessToken="$(System.AccessToken)" ` | ||
| -v:normal | ||
|
|
||
| if ($LASTEXITCODE -ne 0) { | ||
| Write-Error "Failed to publish dashboards to Grafana" | ||
| exit 1 | ||
| } | ||
|
|
||
| Write-Host "" | ||
| Write-Host "==========================================" | ||
| Write-Host "✓ SUCCESS! Dashboards Published" | ||
| Write-Host "==========================================" | ||
| Write-Host "" | ||
| Write-Host "View your dashboards at:" | ||
| Write-Host "$(GrafanaEndpoint)/dashboards" | ||
| Write-Host "" | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use this method with
ExportGrafanaInfoinstead of parameter variables (like e.g.parameters.AMGGrafanaKeyVault)?