-
Notifications
You must be signed in to change notification settings - Fork 0
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
Scaffold project and generate alertmanager dashboard #1
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1090419
Initialise jsonnet project
philipgough 430ec44
Init go mod
philipgough d7e67d4
dashboard: Adds alertmanager jsonnet
philipgough a8cb665
mage: Add alertmanager dashboard target
philipgough bc0ec0c
Generate alertmanager dashboard
philipgough a6451ab
.gitignore
philipgough 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 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 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,25 @@ | ||
local alertmanager = (import 'github.com/prometheus/alertmanager/doc/alertmanager-mixin/dashboards/overview.libsonnet'); | ||
local defaultConfig = (import 'github.com/prometheus/alertmanager/doc/alertmanager-mixin/config.libsonnet'); | ||
local mixin = alertmanager { | ||
_config+:: defaultConfig._config { | ||
alertmanagerClusterLabels: 'namespace,job', | ||
alertmanagerNameLabels: 'pod', | ||
alertmanagerCriticalIntegrationsRegEx: 'slack|pagerduty|email|webhook', | ||
alertmanagerSelector: 'job="alertmanager"', | ||
}, | ||
}; | ||
|
||
{ | ||
apiVersion: 'v1', | ||
kind: 'ConfigMap', | ||
metadata: { | ||
name: 'grafana-dashboard-observatorium-alertmanager-overview', | ||
labels+: { grafana_dashboard: 'true' }, | ||
annotations+: { | ||
'grafana-folder': '/grafana-dashboard-definitions/Observatorium', | ||
}, | ||
}, | ||
data: { | ||
'alertmanager-overview.json': std.manifestJsonEx(mixin.grafanaDashboards['alertmanager-overview.json'], ' '), | ||
}, | ||
} |
This file contains 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,14 @@ | ||
module github.com/rhobs/monitoring | ||
|
||
go 1.23.3 | ||
|
||
require ( | ||
github.com/ghodss/yaml v1.0.0 | ||
github.com/google/go-jsonnet v0.20.0 | ||
github.com/magefile/mage v1.15.0 | ||
) | ||
|
||
require ( | ||
gopkg.in/yaml.v2 v2.2.7 // indirect | ||
sigs.k8s.io/yaml v1.1.0 // indirect | ||
) |
This file contains 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,14 @@ | ||
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= | ||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= | ||
github.com/google/go-jsonnet v0.20.0 h1:WG4TTSARuV7bSm4PMB4ohjxe33IHT5WVTrJSU33uT4g= | ||
github.com/google/go-jsonnet v0.20.0/go.mod h1:VbgWF9JX7ztlv770x/TolZNGGFfiHEVx9G6ca2eUmeA= | ||
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg= | ||
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= | ||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= | ||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= | ||
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= | ||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= |
This file contains 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,15 @@ | ||
{ | ||
"version": 1, | ||
"dependencies": [ | ||
{ | ||
"source": { | ||
"git": { | ||
"remote": "https://github.com/prometheus/alertmanager.git", | ||
"subdir": "doc/alertmanager-mixin" | ||
} | ||
}, | ||
"version": "main" | ||
} | ||
], | ||
"legacyImports": true | ||
} |
This file contains 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,56 @@ | ||
{ | ||
"version": 1, | ||
"dependencies": [ | ||
{ | ||
"source": { | ||
"git": { | ||
"remote": "https://github.com/grafana/grafonnet.git", | ||
"subdir": "gen/grafonnet-latest" | ||
} | ||
}, | ||
"version": "d20e609202733790caf5b554c9945d049f243ae3", | ||
"sum": "V9vAj21qJOc2DlMPDgB1eEjSQU4A+sAA4AXuJ6bd4xc=" | ||
}, | ||
{ | ||
"source": { | ||
"git": { | ||
"remote": "https://github.com/grafana/grafonnet.git", | ||
"subdir": "gen/grafonnet-v11.4.0" | ||
} | ||
}, | ||
"version": "d20e609202733790caf5b554c9945d049f243ae3", | ||
"sum": "aVAX09paQYNOoCSKVpuk1exVIyBoMt/C50QJI+Q/3nA=" | ||
}, | ||
{ | ||
"source": { | ||
"git": { | ||
"remote": "https://github.com/jsonnet-libs/docsonnet.git", | ||
"subdir": "doc-util" | ||
} | ||
}, | ||
"version": "6ac6c69685b8c29c54515448eaca583da2d88150", | ||
"sum": "BrAL/k23jq+xy9oA7TWIhUx07dsA/QLm3g7ktCwe//U=" | ||
}, | ||
{ | ||
"source": { | ||
"git": { | ||
"remote": "https://github.com/jsonnet-libs/xtd.git", | ||
"subdir": "" | ||
} | ||
}, | ||
"version": "1199b50e9d2ff53d4bb5fb2304ad1fb69d38e609", | ||
"sum": "LfbgcJbilu4uBdKYZSvmkoOTPwEAzg10L3/VqKAIWtA=" | ||
}, | ||
{ | ||
"source": { | ||
"git": { | ||
"remote": "https://github.com/prometheus/alertmanager.git", | ||
"subdir": "doc/alertmanager-mixin" | ||
} | ||
}, | ||
"version": "d0eaa9fcd116fd2ef87390cd0f6966b2dfaee6f5", | ||
"sum": "Mf4h1BYLle2nrgjf/HXrBbl0Zk8N+xaoEM017o0BC+k=" | ||
} | ||
], | ||
"legacyImports": false | ||
} |
This file contains 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,71 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/ghodss/yaml" | ||
"github.com/google/go-jsonnet" | ||
"github.com/magefile/mage/mg" | ||
"github.com/magefile/mage/sh" | ||
) | ||
|
||
const ( | ||
vendorPath = "./vendor_jsonnet" | ||
|
||
dashboardSource = "./dashboards/" | ||
dashboardPath = "./resources/dashboards/" | ||
) | ||
|
||
type ( | ||
Dashboards mg.Namespace | ||
) | ||
|
||
// Alertmanager Generates the Alertmanager dashboard | ||
func (d Dashboards) Alertmanager() error { | ||
err := sh.Run("jb", "update", "github.com/prometheus/alertmanager/doc/alertmanager-mixin@main", `--jsonnetpkg-home=vendor_jsonnet`) | ||
|
||
const ( | ||
filename = "alertmanager.jsonnet" | ||
fileOut = "alertmanager.yaml" | ||
) | ||
|
||
vm := getVM() | ||
j, err := vm.EvaluateFile(getDashboardFile(filename)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = writeDashboardFile(fileOut, j) | ||
if err != nil { | ||
return fmt.Errorf("failed to write dashboard file: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
func getVM() *jsonnet.VM { | ||
vm := jsonnet.MakeVM() | ||
vm.Importer(&jsonnet.FileImporter{ | ||
JPaths: []string{ | ||
vendorPath, | ||
}, | ||
}) | ||
return vm | ||
} | ||
|
||
func getDashboardFile(filename string) string { | ||
return fmt.Sprint(dashboardSource, filename) | ||
} | ||
|
||
func writeDashboardFile(filename string, jsonContent string) error { | ||
b, err := yaml.JSONToYAML([]byte(jsonContent)) | ||
if err != nil { | ||
return fmt.Errorf("failed to convert json to yaml: %w", err) | ||
} | ||
|
||
err = os.WriteFile(fmt.Sprint(dashboardPath, filename), b, 0644) | ||
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. I'd do a os.mkdir, just in case 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. this actually fails in terms of idempotency when i added it |
||
if err != nil { | ||
return fmt.Errorf("failed to write file: %w", err) | ||
} | ||
return nil | ||
} |
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.
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.
Let's just panic everywhere. I don't really think returning errors anywhere would help if something were broken
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.
from my understand, from reading the mage docs this s the preferred way because if we start to chain things together then, in targets like
mage dashboards
we can still build the majority of the work without having to bomb outThere 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.
I see, yeah we can follow mage best practices. Although, in our case, would it really matter. Majority of work is the final jsonnet gen step I guess. I'm fine either way