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

metrics-probe: add new parser which generates stats counters #4318

Merged
merged 12 commits into from Feb 28, 2023

Conversation

alltilla
Copy link
Collaborator

@alltilla alltilla commented Feb 9, 2023

This kind of parser counts messages passing through, based on the metadata of each message. It creates labeled stats counters based on the fields of the message. Both the key and labels can be set in the config, the values of the labels can be templated.

Both the key and labels can be set in the config, the values of the labels can be templated. E.g.:

parser p_metrics_probe {
  metrics-probe(
    key("custom_key")  # adds "syslogng_" prefix => "syslogng_custom_key"
    labels(
      "custom_label_name_1" => "foobar"
      "custom_label_name_2" => "${.custom.field}"
    )
  );
};

With this config, it creates counters like these:

syslogng_custom_key{custom_label_name_1="foobar", custom_label_name_2="bar"} 1
syslogng_custom_key{custom_label_name_1="foobar", custom_label_name_2="foo"} 1
syslogng_custom_key{custom_label_name_1="foobar", custom_label_name_2="baz"} 3

The minimal config creates counters with the key syslogng_classified_events_total and labels app, host, program and source. E.g.:

parser p_metrics_probe {
  metrics-probe();

  # Same as:
  #
  # metrics-probe(
  #   key("classified_events_total")
  #   labels(
  #     "app" => "${APP}"
  #     "host" => "${HOST}"
  #     "program" => "${PROGRAM}"
  #     "source" => "${SOURCE}"
  #   )
  # );
};

With this config, it creates counters like these:

syslogng_classified_events_total{app="example-app", host="localhost", program="baz", source="s_local_1"} 3
syslogng_classified_events_total{app="example-app", host="localhost", program="bar", source="s_local_1"} 1
syslogng_classified_events_total{app="example-app", host="localhost", program="foo", source="s_local_1"} 1

Depends on #4325

Signed-off-by: Attila Szakacs szakacs.attila96@gmail.com

@alltilla alltilla marked this pull request as draft February 9, 2023 11:00
@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2023

No news file has been detected. Please write one, if applicable.

@kira-syslogng
Copy link
Contributor

Build FAILURE

@alltilla
Copy link
Collaborator Author

alltilla commented Feb 9, 2023

@kira-syslogng retest this please

alltilla added a commit to alltilla/syslog-ng that referenced this pull request Feb 10, 2023
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
alltilla added a commit to alltilla/syslog-ng that referenced this pull request Feb 15, 2023
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
alltilla added a commit to alltilla/syslog-ng that referenced this pull request Feb 16, 2023
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
alltilla added a commit to alltilla/syslog-ng that referenced this pull request Feb 16, 2023
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
alltilla added a commit to alltilla/syslog-ng that referenced this pull request Feb 16, 2023
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
alltilla added a commit to alltilla/syslog-ng that referenced this pull request Feb 16, 2023
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
alltilla added a commit to alltilla/syslog-ng that referenced this pull request Feb 17, 2023
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
@MrAnno MrAnno self-requested a review February 17, 2023 13:50
alltilla added a commit to alltilla/syslog-ng that referenced this pull request Feb 20, 2023
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
Copy link
Collaborator

@MrAnno MrAnno left a comment

Choose a reason for hiding this comment

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

This is great :)

lib/apphook.c Outdated Show resolved Hide resolved
modules/metrics-probe/metrics-probe.c Outdated Show resolved Hide resolved
modules/metrics-probe/metrics-probe.c Outdated Show resolved Hide resolved
modules/metrics-probe/metrics-probe.c Outdated Show resolved Hide resolved
modules/metrics-probe/metrics-probe.c Outdated Show resolved Hide resolved
modules/metrics-probe/metrics-probe.c Outdated Show resolved Hide resolved
modules/metrics-probe/metrics-probe.c Outdated Show resolved Hide resolved
alltilla added a commit to alltilla/syslog-ng that referenced this pull request Feb 21, 2023
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
alltilla added a commit to alltilla/syslog-ng that referenced this pull request Feb 21, 2023
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
@alltilla alltilla marked this pull request as ready for review February 21, 2023 11:40
MrAnno
MrAnno previously approved these changes Feb 24, 2023
Copy link
Collaborator

@MrAnno MrAnno left a comment

Choose a reason for hiding this comment

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

LGTM.

@MrAnno MrAnno added this to the syslog-ng 4.1 milestone Feb 24, 2023
alltilla added a commit to alltilla/syslog-ng that referenced this pull request Feb 24, 2023
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
alltilla added a commit to alltilla/syslog-ng that referenced this pull request Feb 27, 2023
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
MrAnno
MrAnno previously approved these changes Feb 27, 2023
Copy link
Collaborator

@MrAnno MrAnno left a comment

Choose a reason for hiding this comment

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

👍🏻👍🏻

alltilla added a commit to alltilla/syslog-ng that referenced this pull request Feb 28, 2023
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
MrAnno
MrAnno previously approved these changes Feb 28, 2023
As single stats clusters always store only one counter, we can always
pinpoint that.

Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
This can be useful for plugins, which implement (de)initializable
Thread Local Storage variables.

Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
This kind of parser counts messages passing through, based on the
metadata of each message. It creates labeled stats counters based on the
fields of the message. Both the key and labels can be set in the config,
the values of the labels can be templated.

This commit creates the skeleton for this parser, the implementation
will be done in the following commits.

Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
This will be useful for storing and formatting the label templates set
in the config.

Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
Why do we need to limit the number of labels?

We need allocated memory for the formatted labels, so we can create
a `StatsClusterKey` from them. We could store a buffer for them in the
class, but that would make it stateful, which means we need to lock it
in the `process()` function
Alternatively we could `malloc()` it in each `process()` call, but it
is costly.

If the number of labels is limited, we can allocate them on the stack
in the `process()` function, which means we save a per message
`malloc()` and manage to keep the parser stateless.

The downside is that we put a limit on it, but I don't think that having
more than 32 labels is sensible.

Everything mentioned in this commit message will become cleaner in the
next commits, where the labels get used.

Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
@MrAnno MrAnno merged commit 11f0514 into syslog-ng:master Feb 28, 2023
27 checks passed
Genfood pushed a commit to Genfood/syslog-ng that referenced this pull request Jun 14, 2023
Signed-off-by: Attila Szakacs <szakacs.attila96@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.

None yet

3 participants