Skip to content
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

Enforce Labels on Returned Rules #191

Merged
merged 4 commits into from
Nov 22, 2021
Merged

Enforce Labels on Returned Rules #191

merged 4 commits into from
Nov 22, 2021

Conversation

squat
Copy link
Member

@squat squat commented Nov 14, 2021

Currently, recording and alerting rules that are fetched from the new
rules/raw API will not have any tenant label attached to them. This
means that when the rules are configured on a Thanos Ruler, the time
series that are generated will not have a tenant label on them. This is
a big problem, because without this tenant label, the very tenant to
whom the rules belong cannot query for the time series, making them in
effect useless. This PR enforces that all rules returned by the
rules/raw endpoint have a tenant_id label attached to them.

Note: this is a distinct problem from ensuring that the rules written by
a tenant are guaranteed to only include data from that tenant.
Currently, the rules from a tenant can select data from any tenant. This
is a distinct problem and should absolutely be tackled in a follow up.

In order to be able to apply the labels, we must assert the type of the rules.
Currently, when a group of rules is unmarshaled, the concrete type in Go
will never be a rules.RecordingRule or a rules.AlertingRule, although
those types are defined in the rules package. Instead those rules will
always be some map[string]interface{} type. This means that it's not
possible for users of the package to perform type assertions on the
rules that are fetched via the client, which is a serious annoyance for
anyone using the package.

This PR also fixes this by providing a custom unmarshaling function.
Furthermore, in order to fix unmarshaling via both JSON and YAML, the
PR switches the YAML package to ghodss/yaml, which is a superset of
the current YAML package, go-yaml/yaml.

Finally, rules are either Recording Rules or Alerting Rules, but not both. This
PR fixes this fact in the OpenAPI specification.

Rules are either Recording Rules or Alerting Rules, but not both. This
commit fixes this fact in the OpenAPI specification.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
@squat squat force-pushed the enforce_rules_labels branch from 16b16c7 to 589c6d7 Compare November 14, 2021 22:00
Copy link
Contributor

@jessicalins jessicalins left a comment

Choose a reason for hiding this comment

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

cool, thanks for catching that!
left one question/suggestion

rules/custom_types_test.go Show resolved Hide resolved
rules/custom_types_test.go Show resolved Hide resolved
@squat squat force-pushed the enforce_rules_labels branch 2 times, most recently from f100a51 to d4e5f41 Compare November 16, 2021 14:53
Currently, when a group of rules is unmarshaled, the concrete type in Go
will never be a rules.RecordingRule or a rules.AlertingRule, although
those types are defined in the rules package. Instead those rules will
always be some map[string]interface{} type. This means that it's not
possible for users of the package to perform type assertions on the
rules that are fetched via the client, which is a serious annoyance for
anyone using the package.

This commit fixes this by providing a custom unmarshaling function.
Furthermore, in order to fix unmarshaling via both JSON and YAML, the
commit switches the YAML package to ghodss/yaml, which is a superset of
the current YAML package, go-yaml/yaml.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
@squat squat force-pushed the enforce_rules_labels branch from d4e5f41 to d6fd21b Compare November 16, 2021 14:58
Currently, recording and alerting rules that are fetched from the new
rules/raw API will not have any tenant label attached to them. This
means that when the rules are configured on a Thanos Ruler, the time
series that are generated will not have a tenant label on them. This is
a big problem, because without this tenant label, the very tenant to
whom the rules belong cannot query for the time series, making them in
effect useless. This commit enforces that all rules returned by the
rules/raw endpoint have a tenant_id label attached to them.

Note: this is a distinct problem from ensuring that the rules written by
a tenant are guaranteed to only include data from that tenant.
Currently, the rules from a tenant can select data from any tenant. This
is a distinct problem and should absolutely be tackled in a follow up.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
Copy link
Contributor

@jessicalins jessicalins left a comment

Choose a reason for hiding this comment

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

awesome 🎉
I've created a ticket for the note you mentioned in the description of the PR, so we don't forget about it: https://issues.redhat.com/browse/MON-2063

Copy link
Contributor

@matej-g matej-g left a comment

Choose a reason for hiding this comment

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

Looks good 👍

Copy link
Member

@onprem onprem left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks!!

@onprem onprem merged commit 9401841 into main Nov 22, 2021
@onprem onprem deleted the enforce_rules_labels branch November 22, 2021 10:45
jessicalins pushed a commit to jessicalins/api that referenced this pull request Dec 6, 2021
* rules/spec.yaml: fix enum

Rules are either Recording Rules or Alerting Rules, but not both. This
commit fixes this fact in the OpenAPI specification.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>

* rules: add custom UnmarshalJSON function

Currently, when a group of rules is unmarshaled, the concrete type in Go
will never be a rules.RecordingRule or a rules.AlertingRule, although
those types are defined in the rules package. Instead those rules will
always be some map[string]interface{} type. This means that it's not
possible for users of the package to perform type assertions on the
rules that are fetched via the client, which is a serious annoyance for
anyone using the package.

This commit fixes this by providing a custom unmarshaling function.
Furthermore, in order to fix unmarshaling via both JSON and YAML, the
commit switches the YAML package to ghodss/yaml, which is a superset of
the current YAML package, go-yaml/yaml.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>

* rules/rules.go: regenerate

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>

* api: enforce tenant on generated time series

Currently, recording and alerting rules that are fetched from the new
rules/raw API will not have any tenant label attached to them. This
means that when the rules are configured on a Thanos Ruler, the time
series that are generated will not have a tenant label on them. This is
a big problem, because without this tenant label, the very tenant to
whom the rules belong cannot query for the time series, making them in
effect useless. This commit enforces that all rules returned by the
rules/raw endpoint have a tenant_id label attached to them.

Note: this is a distinct problem from ensuring that the rules written by
a tenant are guaranteed to only include data from that tenant.
Currently, the rules from a tenant can select data from any tenant. This
is a distinct problem and should absolutely be tackled in a follow up.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>

Start e2e test

Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants