Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Add cortex ruler endpoints #7

Merged
merged 5 commits into from
Feb 19, 2021
Merged

Add cortex ruler endpoints #7

merged 5 commits into from
Feb 19, 2021

Conversation

papagian
Copy link
Collaborator

@papagian papagian commented Feb 18, 2021

Introduces a new GrafanaManagedAlert rule type (besides existing Record and Alert) with exposed properties.

Comment on lines 102 to 103
//GrafanaManagedAlert yaml.Node `yaml:"grafana_alert,omitempty"`
GrafanaManagedAlert ExtendedUpsertAlertDefinitionCommand `yaml:"grafana_alert,omitempty"`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to expose the GrafanaManagedAlert properties instead of having it as yaml.Node (the commented line)

// swagger:model
type RuleGroupConfig struct {
Name string `yaml:"name"`
Interval model.Duration `yaml:"interval,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add json field tags as well?

UpsertAlertDefinitionCommand
NoDataState NoDataState `json:"no_data_state"`
ExecutionErrorState ExecutionErrorState `json:"exec_err_state"`
Settings map[string]interface{} `json:"settings"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's stored in settings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dashboard alerts used to have such a field and NoDataState and ExecutionErrorState used be there. I don't know if some existing dashboard alerts have some additional settings therefore I have kept it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I heard that backenders are trying to figure out what to do with these states in the new alerting system, I guess things will be clarified later

OrgID int64 `json:"org_id"`
Condition string `json:"condition"`
Data []eval.AlertQuery `json:"data"`
IntervalSeconds *int64 `json:"intervalSeconds"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be configurable per group rather than on individual alerts

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right; I kept it just because it's in the existing model in grafana repo (from where I have copied it because it's not exported). I've changed it to:

	// IntervalSeconds is an obsolete field (it will derive from the ruleGroup interval)
	IntervalSeconds *int64            `json:"-"

so it's not required to be passed in the request.
Is that any better?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure! we can always refine details later once things come into focus more

https://github.com/grafana/grafana/blob/debb82e12417e82a0e2bd09e1a450065f884c1bc/pkg/services/ngalert/models.go#L85
type UpsertAlertDefinitionCommand struct {
Title string `json:"title"`
OrgID int64 `json:"org_id"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't org implicit, user's current org?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: I have changed it to:

	// OrgID is an obsolete field (it will derive from the x-grafana-org-id header)
	OrgID           int64             `json:"-"`

so it's not required to be passed in the request.
Is that any better?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

Data []eval.AlertQuery `json:"data"`
IntervalSeconds *int64 `json:"intervalSeconds"`
// UID exists is set only for existing definitins
UID string `json:"uid"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the prometheus way is to rely on name, there are no IDs for rules. Not usre it makes sense to have one for grafana managed alerts specifically

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need it because in grafana we identify all the entities by UID and we have versioning for the rules so we need to be able to tell when a rule is created or updated and I don't think we want to relay on the name (it can be also hard for the migration of the existing dashboards alerts).
This field will be empty when the rule is created and the grafana backend will assign one UID and will included in the GET responses.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, let's keep it for now

- /api/v1/rules/{Namespace} should return a map
- update ExtendedUpsertAlertDefinitionCommand properties
@domasx2 domasx2 self-requested a review February 19, 2021 08:48
@papagian papagian merged commit e721368 into master Feb 19, 2021
@papagian papagian deleted the add-rules-endpoints branch February 19, 2021 10:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants