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

Cortex Alertmanager fails to load template filenames which contain directories #3357

Closed
mattmendick opened this issue Oct 15, 2020 · 8 comments
Labels

Comments

@mattmendick
Copy link
Contributor

Describe the bug
Alertmanager has functionality to receive templates and use them with the provided rules files. However I believe the directory processing logic has a bug in it which causes a failure.

To Reproduce
To see the error message, where 999999 is the tenant ID:

Using the cortextool utility (from https://github.com/grafana/cortex-tools) with this command:

./cortextool alertmanager load --id 999999 --address https://alertmanager.url.here --key $ALERTMANAGER_API_KEY alerting/policies/alerts.yml alerting/policies/thetemplatefile.tmpl

Yields the error:

error validating Alertmanager config: unable to create Alertmanager template file \"/tmp/validate-config197042527/templates/999999/alerting/policies/alerting/policies/thetemplatefile.tmpl\": open /tmp/validate-config197042527/templates/999999/alerting/policies/alerting/policies/thetemplatefile.tmpl: no such file or directory\n" status="400 Bad Request"

Expected behavior
It should be able to create the file at the right directory and use it.

Additional Context
I believe the issue is this:

If you provide a filename like some/path/templatefile.tmpl it will create datadir/some/path/ and then try to write datadir/some/path/some/path/templatefile.tmpl

Creating directory at:

dir := filepath.Join(dataDir, "templates", userID, filepath.Dir(fn))

But using the entire path at:

file := filepath.Join(dir, fn)

550 should be something like file := filepath.Join(dir, filepath.Base(fn)) to only add templatefile.tmpl to the dir already created.

@gotjosh
Copy link
Contributor

gotjosh commented Oct 16, 2020

Hey @mattmendick ! Thanks for reporting this one.

Sadly, we don't support paths (only filenames) as part of the Alertmanager template definitions.

The key difference here is that unlike Prometheus cortex does not have a need to "look" for these files as we store them in object storage (and then write it to disk temporarily to consume it).

An alternative to what you proposed, to have a clearer error message to signal that this is not supported and make it clear in the documentation. I can see the appeal of just making it work for our users but I'm generally I'm the opposite side of modifying users configuration.

@mattmendick
Copy link
Contributor Author

Thanks @gotjosh, I created grafana/cortex-tools#114 to address the issue on the cortextool side.

@stale
Copy link

stale bot commented Jan 12, 2021

This issue has been automatically marked as stale because it has not had any activity in the past 60 days. It will be closed in 15 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 12, 2021
@jtlisi
Copy link
Contributor

jtlisi commented Jan 15, 2021

still valid

@stale stale bot removed the stale label Jan 15, 2021
@stale
Copy link

stale bot commented Apr 17, 2021

This issue has been automatically marked as stale because it has not had any activity in the past 60 days. It will be closed in 15 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 17, 2021
@pracucci
Copy link
Contributor

We recently discussed it and it's currently the intended behaviour.

@Carmezim
Copy link

Carmezim commented Apr 20, 2021

I am having a similar issue when trying to configure the alertmanager

cortextool alertmanager load ./alertmanager_config.yml

yields:

error validating Alertmanager config: mkdir /tmp/validate-config001396953: read-only file system

Similarly through the API directly

@pracucci
Copy link
Contributor

error validating Alertmanager config: mkdir /tmp/validate-config001396953: read-only file system

This is a different issue. Let's discuss it in the dedicated issue you've opened #4089.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants