-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Add Prometheus 2 service in parallel with 1.x version #49802
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
Conversation
promUser = "prometheus"; | ||
promGroup = "prometheus"; | ||
prom2User = "prometheus2"; |
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.
I suspect it would be acceptable (preferable, even?) to have prometheus and prometheus2 share the same UID/GID, unless there's a reason that won't work.
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.
@benley It's centainly preferable to have just one user. As of now the data dir /var/lib/prometheus(2) is also the home of the user and that's is used to create the dir and to ensure that the dir is automatically owned by it. I have yet to find out what's the best way to proceed if the data dirs are two. What you advise me to do?
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.
Hrm, good question. I suppose you could put prometheus 2 data in a subdirectory of prometheus 1's data, but that introduces some danger when someone goes to delete their old prometheus 1 data dir once they're finished migrating. Maybe the systemd unit could create the new data dir before starting the prometheus daemon?
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.
see systemd.tmpfiles.rules in other modules to create dirs.
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.
You can also create the directory with
serviceConfig = { StateDirectory = "prometheus2" };
in the systemd config
|
||
cmdlineArgs2 = cfg2.extraFlags ++ [ | ||
"--storage.tsdb.path=${cfg2.dataDir}/data/" | ||
"--config.file=${prometheusYml}" |
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.
"--config.file=${prometheusYml}" | |
"--config.file=${prometheus2Yml}" |
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.
Did some test of your new module - seems to be a error here - new prometheus2 configuration will not be generated. Thanks for your work! BR Erik
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.
This is was integrated
I would like to test this, could you please update it for master? |
As the configuration for the exporters and alertmanager is unchanged between the two major versions this patch tries to minimize duplication while at the same time as there's no upgrade path from 1.x to 2.x, it allows running the two services in parallel. See also NixOS#56037
fefe775
to
978f25c
Compare
@ivan I've rebased the patch and integrated all the changes that happened on master, can/will you test it out? |
There is some syntax error in the alertmanager module
|
@eonpatapon should be fixed now |
@azazel75 why did you also make 2 services for each of the exporters? They look to be the exact same services but configured to be under |
Sorry @griff but I don't understand precisely what your arguments against two set of exporters configurations are. their configuration modules access their own configuration stored as services.prometheus.exporters.foo or services.prometheus2.exporters.foo. Maybe for the "node" exporter can't be more than one exporter configured in a system, but generally speaking maybe in a situation where both prometheus1 and 2 are running there could be the need for concurrent running of two exporters of the same type. I don't have a concrete example though. |
@azazel75 I may have missunderstod how the exporters work but let me try and explain my point better with my understanding. As such exporters are http servers that will get called by the prometheus server at an interval. My understanding is that there is no problem with two prometheus servers calling the same exporter at different intervals. i.e. they don't disturb each other and state is not reset on a scrape. If this is correct running the same exporter twice is just a waste of CPU and RAM since just one can be scraped from multiple servers and having multiple services that allow you to run the same exporter twice signals that you need to run them twice if running both prometheus 1 & 2. |
>>>> "Brian" == Brian Olsen ***@***.***> writes:
Brian> @azazel75 I may have missunderstod how the exporters work but let me try and explain my point better with my understanding.
Brian> As such exporters are http servers that will get called by the
Brian> prometheus server at an interval. My understanding is that there is no
Brian> problem with two prometheus servers calling the same exporter at
Brian> different intervals. i.e. they don't disturb each other and state is
Brian> not reset on a scrape. If this is correct running the same exporter
Brian> twice is just a waste of CPU and RAM since just one can be scraped
Brian> from multiple servers and having multiple services that allow you to
Brian> run the same exporter twice signals that you need to run them twice if
Brian> running both prometheus 1 & 2.
I think that your reasoning has some has a weakness. I think that there
can be some reasons why two exporters of the same type run e.g:
- the two prometheus monitor a set of different service in the process
of being upgraded, where the services whose data is collected by
exporter foo-A are different (and so a different config is needed) by
those whose data is collected by foo-B, where the first is collected
by prometheus1 and the second by prometheus2
- the exporter needs to present the data to prometheus1 and 2 in
different way (different aggregation, different precision) to the two
monitoring agents, so one quick way may be to configure two of them,
with different configuration parameters, and dismiss the one connected
to prometheus1 when it will be... deleted.
but anyway, it isn't a great complication in the config files of the
exporters, they just take in their parent configuration attr as a
variable instead of as a constant. It may well become useful if there
will be a Prometheus3 someday. At the same time I'm against over
engineering the configuration so if you (you that have merge permission)
think that it's too much, it surely can be simplified. In that case I
think the configuration should emphasize that the configuration of the
exporters is somewhat independent from the two prometheus services and
that it doesn't belong to one in particular.
|
@azazel75 I think a clean copy and past of prometheus would be easier to maintain if we say that we want to get rid of prometheus 1 in the long run. I'm with @griff for the exporters. From my experience they are completly independet of the prometheus version you are running. So I would not add additional services for them. |
@azazel75 I am sorry if I wrongly gave the impression that I am any kind of authority on this subject or that I have merge permissions. I am just a normal user like yourself that wants NixOS to be as great as possible and therefore offered my personal opinions. As for your response of wanting to run different exporters with different parameters the question I have is why then only allow 2? The prometheus exporter format is becoming pretty standard and supported by other metrics solutions (like telegraf and DataDog to mention just 2) so if the argument is that we want to support different scrapers hitting the same exporter type run with different arguments why not allow me to run the same exporter 3 times or as many times as I want? |
This is an issue that affects variety of services in NixOS, and probably not one we should try to solve in this PR. The existing pattern of |
There is still an issue with alertmanager module, here's the patch to fix it:
|
Thanks @eonpatapon. @griff there's no need to worry. It's just that I don't have the power to merge this either but to answer your example of running more that two sets of exporters, it seems out of scope. Anyway I'm running out of time that I want to spend on this, feel free to take what you need and propose your own or directly modify this ( If I can do something about that, just tell me and I wil do It) |
@@ -4,8 +4,10 @@ with lib; | |||
|
|||
let | |||
cfg = config.services.prometheus.exporters; | |||
cfg2 = config.services.prometheus2.exporters; |
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.
Having two sets of exports does not make any sense. Please remove these changes.
in { | ||
options = { | ||
services.prometheus.alertmanager = { | ||
cfg2 = config.services.prometheus2.alertmanager; |
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.
A second instance/version of alertmanager does not make sense. Prometheus sends queries to alertmanager to trigger alerts, so one instance is enough.
@@ -339,6 +339,7 @@ | |||
rss2email = 312; | |||
cockroachdb = 313; | |||
zoneminder = 314; | |||
prometheus2 = 315; |
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.
One user for both prometheus instances would be enough. Especially because we are going to remove prometheus1 soon.
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.
I agree.
@disassembler, @jbgi please go for it. The only detail you have to pay attention to is the creation of the working directory if you are going to use just one user for both the services in such case, one directory is created as home of the user, the other needs to be created when the service is enabled. The proposed solutions involve the use of |
I would in both cases use This also makes it possible to later switch to |
Added some more commits in #58255 to address the points raised. |
Let's close this PR in favour of #58255 which includes the commits of this PR and fixes the remaining issues. |
Motivation for this change
Cleaned up version of #46069. The reason for this is that there's no clean upgrade path from 1.x to 2.x, the suggested solution by the Prometheus team is that of let them run in parallel an use the 1.x instance as source for the 2.x.
in the original PR someone suggested a more copy and paste approach. I don't know, I don't really need Prometheus 1.x. So is up to you to decide
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)