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

Limit dynamic counters #1743

Merged
merged 4 commits into from Nov 15, 2017
Merged

Conversation

lbudai
Copy link
Collaborator

@lbudai lbudai commented Oct 27, 2017

Add config option for limiting dynamic counters
  • Users can limit the number of registered dynamic counters via the stats_max_dynamics global option.
    This is not a limit for the number of counters but for the number of clusters which means that users
    can limit the number of different dynamic value occurrences (as each
    cluster has a pre-allocated array of counters).

  • Note that after reload, when users set a lower limit,
    they have to wait for stat-freq-timer being expired to remove the
    previously allocated dynamic clusters.

  • Dynamic values are

    • source host (from stats level 2)
    • sender host (host from) (from stats level 3)
    • program (from stats level 3)
  • By default this change is backward compatible: if someone not uses this feature, number of dynamic counters won't be limited.

  • It is possible to disable dynamic counters by setting the limit to 0.

The following example contains 6 different dynamic values (a sender, a host and four different programs):
    src.sender;;localhost;d;processed;4
    src.sender;;localhost;d;stamp;1509121934
    src.program;;P-18069;d;processed;1
    src.program;;P-18069;d;stamp;1509121933
    src.program;;P-21491;d;processed;1
    src.program;;P-21491;d;stamp;1509121934
    src.program;;P-9774;d;processed;1
    src.program;;P-9774;d;stamp;1509121919
    src.program;;P-14737;d;processed;1
    src.program;;P-14737;d;stamp;1509121931
    src.host;;localhost;d;processed;4
    src.host;;localhost;d;stamp;1509121934

Questions to reviewers:

  • What do you think about storing dynamic counters in a separate hash table?
  • What do you think about the reload-issue? (when the user sets a lower value, after a reload the already registered dynamic counters won't be removed until start-freq timer not expires)?

Iterate through the hashtable items requires to grab the mutex
(stats_lock).

Signed-off-by: Laszlo Budai <laszlo.budai@balabit.com>
Signed-off-by: Laszlo Budai <laszlo.budai@balabit.com>
Signed-off-by: Laszlo Budai <laszlo.budai@balabit.com>
@kira-syslogng
Copy link
Contributor

Build SUCCESS, the tests were executed on test branch: master and test suite: functions

@kira-syslogng
Copy link
Contributor

Build SUCCESS, the tests were executed on test branch: master and test suite: functions

@kira-syslogng
Copy link
Contributor

Build SUCCESS, the tests were executed on test branch: master and test suite: functions

return NULL;
sc = stats_cluster_dynamic_new(sc_key);
_insert_cluster(sc);
if ( !stats_check_dynamic_clusters_limit(_number_of_dynamic_clusters()))
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary space here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm... we have a tool that checks style and blocks merge until we fix format issues.
So I wouldn't fix it here (fixing astyle would be better as currently we don't check this kind of format issue and it is possible that there are other parts of the code which is affected by the same problem).

@bodnartibi
Copy link
Contributor

Looks good to me.

static StatsClusterContainer stats_cluster_container;

static guint
_number_of_dynamic_clusters()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing void in the parameter list

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

{
msg_warning("Number of dynamic cluster limit has been reached.",
evt_tag_int("allowed clusters", stats_number_of_dynamic_clusters_limit()));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use underscore in the tag name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Users can set this via the `stats_max_dynamics` global option.
This is not the number of counters but clusters which means that users
can limit the number of different dynamic value occurrences (as each
cluster has a pre-allocated array of counters).

Note that after reload, when users set a lower limit,
they have to wait for stat-freq-timer being expired to remove the
previously allocated dynamic clusters.

Dynamic values are
 * source host (from stats level 2)
 * sender host (host from) (from stats level 3)
 * program (from stats level 3)

The following example contains 6 different dynamic values (a sender, a
host and four different programs):

src.sender;;localhost;d;processed;4
src.sender;;localhost;d;stamp;1509121934
src.program;;P-18069;d;processed;1
src.program;;P-18069;d;stamp;1509121933
src.program;;P-21491;d;processed;1
src.program;;P-21491;d;stamp;1509121934
src.program;;P-9774;d;processed;1
src.program;;P-9774;d;stamp;1509121919
src.program;;P-14737;d;processed;1
src.program;;P-14737;d;stamp;1509121931
src.host;;localhost;d;processed;4
src.host;;localhost;d;stamp;1509121934

Signed-off-by: Laszlo Budai <laszlo.budai@balabit.com>
@kira-syslogng
Copy link
Contributor

Build SUCCESS, the tests were executed on test branch: master and test suite: functions

@@ -264,6 +264,15 @@ stats_cluster_new(const StatsClusterKey *key)
return self;
}

StatsCluster *
stats_cluster_dynamic_new(const StatsClusterKey *key)
Copy link
Contributor

Choose a reason for hiding this comment

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

I rather use a parameter for the constructor.
Based on the signature of this function it seems that we have two different object for dynamic and static clusters, while they differs only in one attribute.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We talked about this IRL, here is my short answer: I think dynamic cluster represents a different (sub)type (it behaves differently than the non-dynamic clusters) and we already provide a different API for dynamic counters (note: there is no dynamic counter, but dynamic cluster, what makes a counter dynamic is that the counter is registered with one of the _dynamic function which track the counter inside a dynamic cluster).
So I think this is not only a simple attribute: this is a kind of type selector and we actually make behavioral decisions based on the value of this attribute.


g_assert(sc->dynamic == dynamic);
}
if (!sc)
Copy link
Contributor

Choose a reason for hiding this comment

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

In what circumstances can sc be falsy here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I see, in the next commit it can be NULL.

@@ -931,6 +932,7 @@ stat_option
: KW_STATS_FREQ '(' nonnegative_integer ')' { last_stats_options->log_freq = $3; }
| KW_STATS_LEVEL '(' nonnegative_integer ')' { last_stats_options->level = $3; }
| KW_STATS_LIFETIME '(' positive_integer ')' { last_stats_options->lifetime = $3; }
| KW_STATS_MAX_DYNAMIC '(' nonnegative_integer ')' { last_stats_options->max_dynamic = $3; }
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the default value of this option? What will be on the documentation? As I see:

  • >0 means the limit of the dynamic stat clusters
  • 0 means disable storing dynamic stat clusters
  • -1 means there is no limit - but it is not a valid value here...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

-1 is cannot be set by users in the config, it is the default value, so when the option is not set then number of dynamic counters are unlimited as before.

@lbudai
Copy link
Collaborator Author

lbudai commented Nov 8, 2017

@fekete-robert : some documentation related notes

  • @presidento pointed out that the default value (-1) cannot be set by users, so if someone don't need this feature(->don't want to limit the number of dynamic counters), he or she has to remove the option from the config (and this is intentional from my part)
  • reload won't clear dynamic counters (hin: lifetime, stats-freq)

@fekete-robert
Copy link
Collaborator

fekete-robert commented Nov 9, 2017 via email

@Kokan Kokan merged commit a35f9b4 into syslog-ng:master Nov 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants