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

Expose full support for file globs for rules #2487

Closed
dacameron opened this Issue Mar 9, 2017 · 9 comments

Comments

Projects
None yet
4 participants
@dacameron
Copy link

dacameron commented Mar 9, 2017

What did you do?
Tried putting a file glob for rule_files:

/etc/prometheus/rules/*/*.rule

What did you expect to see?
Rules loaded like:

/etc/prometheus/rules/service_A/some.rule
/etc/prometheus/rules/service_B/another.rule

What did you see instead? Under which circumstances?

Invalid rule file path "/etc/prometheus/rules/*/*.rule"

and prometheus doesn't load.

To work around this I padded the service names so they are always 16 chars and added a rule:
/etc/prometheus/rules/????????????????/*.rule

a total hack but it works for now.

I am happy to send a pull request to fix the regex in config.go. But I am not sure if this is by design? or can the rule file path regex in config.go be improved?

The main use case is to have rules for different services in different directories. When deploying those services we can blow away the old rules by blowing away the directory with the rules, adding the new rules and then reloading prometheus.

@brancz

This comment has been minimized.

Copy link
Member

brancz commented Mar 9, 2017

I think this is a valid use case. I would be interested as well why this decision was made. But it was before my time, so I would ask @beorn7 @brian-brazil @fabxc @juliusv as to why this decision was made. What would be the problem with a standard file glob?

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Mar 9, 2017

Would that work with inotify?

@brancz

This comment has been minimized.

Copy link
Member

brancz commented Mar 9, 2017

I wasn't aware that rule files are watched and reloaded. I think in that case a watch per subdirectory has to be instantiated, and gets more complicated when you want to dynamically add new directories to watch when they're added.

@brancz

This comment has been minimized.

Copy link
Member

brancz commented Mar 9, 2017

Also the documentation makes it sound like file globs work:

# Rule files specifies a list of globs. Rules and alerts are read from
# all matching files.
rule_files:
  [ - <filepath_glob> ... ]
@dacameron

This comment has been minimized.

Copy link
Author

dacameron commented Mar 9, 2017

I can see how adding watched rule support would be useful, and I think doing this with full glob support would be a world of pain.

But you need to be more limiting in your allowed file globs. Someone could be using ? between separators now which means inotify won't work as is. So in any case the regex needs to be patched to either be more permissive or more restrictive.

I'll stop doing my ? between separators hack and I will just prefix rules in one directory when I deploy them. This achieves the same purpose and is future proof for whatever you decide to do.

@jwhitlark

This comment has been minimized.

Copy link

jwhitlark commented Mar 14, 2018

Can we please have updated documentation on what file path support is available? I'd do a PR myself, but as it isn't actually a glob, I don't know what it actually supports.

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Mar 15, 2018

A glob is supported in the filename, looks like both rule_files and file_sd_configs are missing that detail.

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Mar 21, 2018

I don't think it would make sense to have this in one place and not the other, as that'd just cause confusion. Let's stick with just a glob in the file name.

@lock

This comment has been minimized.

Copy link

lock bot commented Mar 22, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Mar 22, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.