-
Notifications
You must be signed in to change notification settings - Fork 500
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
Add util class to support to add annotations to Grafana #378
Conversation
pkg/util/annotationUtil.go
Outdated
|
||
//IncreErrorCountWithAnno increments the errorcount by 1, | ||
//and add the annotation to grafanan. | ||
func (cli *client) IncreErrorCountWithAnno(annotation Annotation) error{ |
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.
we don't need this method. only addAnnotation
is needed.
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.
Split it as two functions
1.AddAnnotation
2.IncrErrorCount
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.
Prefer underscore case for file name (e.g. annotation_util.go
).
Rest LGTM.
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.
Almost fine, the last concern is some fields are optional and some fields are missing (isRange
, timeEnd
)
tests/metrics/annotation_util.go
Outdated
//Annotation is a specification of the desired behavior of adding annotation | ||
type Annotation struct { | ||
DashboardId int `json: "dashboardId"` | ||
PanelId int `json: "panelId"` |
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.
DashboardId
and PanelId
are optional, so we should omit these field is empty (nil for pointer, 0 for numeric type), the notation is json:"dashboardId,omitempty"
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.
So do tags
.
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.
dashboardId和pannelId明显是不能忽略的啊,要不然知道加哪张图上
tags accept
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.
The scenario is that users may add the global annotation (without DashboardId
and PanelId
) to grafana and query it in multiple dashboards. To me it is the common case because when I am coding I cannot ensure the grafana dashboard id and panel id is consistent in different clusters and different e2e tests or stability tests.
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.
can we post an annotation without dashboardID and panelID?
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.
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.
We can leave them optional for a wider range of uses. @qiffang
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 the original requirement, we want to add annotation in a graph(panel).
Of course, we can support it.
Accept
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.
Great! There is a small typo however, rest LGTM.
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.
LGTM
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.
lgtm
* helm offline * fix ci * tiny fix * Apply suggestions from code review Co-authored-by: Ran <huangran@pingcap.com> * Update zh/tidb-toolkit.md Co-authored-by: DanielZhangQD <36026334+DanielZhangQD@users.noreply.github.com> Co-authored-by: Ran <huangran@pingcap.com> Co-authored-by: DanielZhangQD <36026334+DanielZhangQD@users.noreply.github.com>
Function
Prometheus can scrape this metric by xxx:8083/metrics.
Usage
cli, _ := NewGrafanaClient("http://$GrafanaIP:3000", "$GrafanaUserName", "$GrafanaPassword", "$PrometheusScrapePort")
annotation := Annotation{ dashboardId: $dashboardId, panelId: $panelId, tags: []string{"tag"}, timestampInMilliSec: time.Now().Unix() * 1000, text: "test", }
cli.AddAnnotation(annotation)
cli.IncrErrorCount()
Test