-
Notifications
You must be signed in to change notification settings - Fork 69
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
Analyse grafana: Use minimal schema #247
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package analyse | ||
|
||
type ( | ||
Board struct { | ||
ID uint `json:"id,omitempty"` | ||
UID string `json:"uid,omitempty"` | ||
Slug string `json:"slug"` | ||
Title string `json:"title"` | ||
Panels []*Panel `json:"panels"` | ||
Rows []*Row `json:"rows"` | ||
Templating Templating `json:"templating"` | ||
} | ||
Templating struct { | ||
List []TemplateVar `json:"list"` | ||
} | ||
TemplateVar struct { | ||
Name string `json:"name"` | ||
Query interface{} `json:"query"` | ||
Type string `json:"type"` | ||
} | ||
Panel struct { | ||
Targets []Target `json:"targets,omitempty"` | ||
Title string `json:"title"` | ||
Panels []Panel `json:"panels"` // row panel type | ||
Type string `json:"type"` | ||
} | ||
Target struct { | ||
RefID string `json:"refId"` | ||
Datasource string `json:"datasource,omitempty"` | ||
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 will not parse modern dashboards, where this is an object. So we still need either #239 or my change from grafana-tools/sdk#201 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. Ah I don't think this field actually gets used anywhere at the moment, so i could remove it. However if we fork, I agree that it makes more sense to just use the fork instead of the above approach. 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 have a fork at https://github.com/colega/grafana-tools-sdk which you can use here as go mod replacement if you need, I've been merging all the fixes into master there. |
||
// For Prometheus | ||
Expr string `json:"expr,omitempty"` | ||
} | ||
Row struct { | ||
Panels []Panel `json:"panels"` | ||
} | ||
) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -24,7 +24,13 @@ type GrafanaAnalyseCommand struct { | |||||
} | ||||||
|
||||||
func (cmd *GrafanaAnalyseCommand) run(k *kingpin.ParseContext) error { | ||||||
output := &analyse.MetricsInGrafana{} | ||||||
var ( | ||||||
boardLinks []sdk.FoundBoard | ||||||
rawBoard []byte | ||||||
board analyse.Board | ||||||
err error | ||||||
output *analyse.MetricsInGrafana | ||||||
) | ||||||
output.OverallMetrics = make(map[string]struct{}) | ||||||
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), cmd.readTimeout) | ||||||
|
@@ -35,15 +41,20 @@ func (cmd *GrafanaAnalyseCommand) run(k *kingpin.ParseContext) error { | |||||
return err | ||||||
} | ||||||
|
||||||
boardLinks, err := c.SearchDashboards(ctx, "", false) | ||||||
boardLinks, err = c.SearchDashboards(ctx, "", false) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
for _, link := range boardLinks { | ||||||
board, _, err := c.GetDashboardByUID(ctx, link.UID) | ||||||
rawBoard, _, err = c.GetRawDashboardBySlug(ctx, link.URI) | ||||||
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. Nit: I'd keep |
||||||
if err != nil { | ||||||
fmt.Fprintf(os.Stderr, "%s for %s %s\n", err, link.UID, link.Title) | ||||||
fmt.Fprintf(os.Stderr, "%s for %s\n", err, link.URI) | ||||||
continue | ||||||
} | ||||||
|
||||||
if err = json.Unmarshal(rawBoard, &board); err != nil { | ||||||
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. Nit:
Suggested change
Even if the outcome is the same, we don't really want to modify the outer |
||||||
fmt.Fprintf(os.Stderr, "%s for %s\n", err, link.URI) | ||||||
continue | ||||||
} | ||||||
analyse.ParseMetricsInBoard(output, board) | ||||||
|
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.
I would write a comment in this mentioning the purpose of these (same thing you wrote on the PR description) to avoid someone coming and completing it with all fields.