Skip to content

Replace ':' with '_' in stats name.#1806

Merged
junr03 merged 7 commits intoenvoyproxy:masterfrom
hennna:remove-colon-name-restriction
Oct 4, 2017
Merged

Replace ':' with '_' in stats name.#1806
junr03 merged 7 commits intoenvoyproxy:masterfrom
hennna:remove-colon-name-restriction

Conversation

@hennna
Copy link
Copy Markdown
Contributor

@hennna hennna commented Oct 4, 2017

Do a character replacement (':' to '_') in ScopeImpl to remove ':' restriction in user defined names. Stats must be created in a dedicated scope.

This PR handles cases that can be resolved by removing invalid character during stats scope creation (ex: cluster name and listener addresses). This PR is not general enough to allow arbitrary naming of counters, gauges, and histograms. The PR also does not reconcile accessing stats using unsanitized stats name.

Fixes #1782

Signed-off-by: Henna Huang henna@google.com

Signed-off-by: Henna Huang <henna@google.com>
"#/properties/name\n Schema violation: pattern\n Offending document "
"key: #/name");
create(parseBootstrapFromJson(json));
EXPECT_EQ(0, factory_.stats_.counter("cluster.cluster_name.lb_local_cluster_not_ok").value());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Are there any non-zero stats that I can check here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't you check any cluster stat that is per-cluster, adding a : in there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Signed-off-by: Henna Huang <henna@google.com>
*(required, string)* Supplies the name of the cluster which must be unique across all clusters.
The cluster name is used when emitting :ref:`statistics <config_cluster_manager_cluster_stats>`.
The cluster name can be at most 60 characters long, and must **not** contain ``:``.
The cluster name can be at most 60 characters long.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably a good idea to document the s/:/_/ that happens in cluster stats output.

per_connection_buffer_limit_bytes_(
PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, per_connection_buffer_limit_bytes, 1024 * 1024)),
stats_scope_(stats.createScope(fmt::format("cluster.{}.", name_))),
stats_scope_(stats.createScope(clusterStatsName(name_))),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thoughts on just moving the replace into the implementation of createScope() ? This would cover LDS also and any future cases. @junr03 you should create a scope for RDS stats so that if route table name has ':' in it it would also be fixed. I realize that RDS/LDS also have potential length issues but that is orthogonal to this.

Copy link
Copy Markdown
Member

@junr03 junr03 Oct 4, 2017

Choose a reason for hiding this comment

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

yup, was following #1782. @hennna I don't want to duplicate your efforts here, lets decide if you are going to move the replace into the implementation of createScope(). If you do, then I don't have to fix anything, if you don't then I will update #1805.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@junr03 I've updated to push the character replacement in ScopeImpl. I believe this should work for you also.

hennna added 2 commits October 4, 2017 14:27
Signed-off-by: Henna Huang <henna@google.com>
Signed-off-by: Henna Huang <henna@google.com>
@hennna hennna changed the title Replace ':' with '_' in stats cluster name. Replace ':' with '_' in stats name. Oct 4, 2017
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM. This is all very-statsd specific, I hope we don't run into situations with other stats sinks which have their own formatting constraints; @mrice32.

std::replace(final_stat_name.begin(), final_stat_name.end(), ':', '_');
listener_scope_ = parent_.server_.stats().createScope(final_stat_name);
listener_scope_ =
parent_.server_.stats().createScope(fmt::format("listener.{}.", address_->asString()));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: may also want to validate this in a unit test.

~ScopeImpl();
// ':' is a reserved char in statsd. Do the translation here and in
// IsolatedStoreImpl::ScopeImpl.
std::string sanitizeStatsName(const std::string& name) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we move this into a common utility function.

@mrice32
Copy link
Copy Markdown
Member

mrice32 commented Oct 4, 2017

@htuch I think we have a few choices when it comes to future sinks having similar formatting constraints:

  1. Accept that is a possibility and be open to handling it upstream on a case-by-case basis.
  2. Do generalized preprocessing of stats (configured separately from sinks because sinks can be mixed and matched) in a similar fashion to our plan for tags where one would be able to apply universal name changes through the config.
  3. Force sinks to do this transformation on each flush (or establish a mapping) which would incur a latency penalty.

hennna added 3 commits October 4, 2017 16:15
Signed-off-by: Henna Huang <henna@google.com>
Signed-off-by: Henna Huang <henna@google.com>
Signed-off-by: Henna Huang <henna@google.com>
@junr03 junr03 merged commit e7f454c into envoyproxy:master Oct 4, 2017
htuch added a commit to htuch/envoy-api that referenced this pull request Oct 30, 2017
In response to envoyproxy/envoy#1806 and
envoyproxy/envoy#1871.

Signed-off-by: Harvey Tuch <htuch@google.com>
htuch added a commit to envoyproxy/data-plane-api that referenced this pull request Oct 30, 2017
In response to envoyproxy/envoy#1806 and
envoyproxy/envoy#1871.

Signed-off-by: Harvey Tuch <htuch@google.com>
@hennna hennna deleted the remove-colon-name-restriction branch December 20, 2017 18:25
jpsim pushed a commit that referenced this pull request Nov 28, 2022
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: JP Simard <jp@jpsim.com>
Elite1015 pushed a commit to Elite1015/data-plane-api that referenced this pull request Feb 23, 2025
In response to envoyproxy/envoy#1806 and
envoyproxy/envoy#1871.

Signed-off-by: Harvey Tuch <htuch@google.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.

remove ':' restriction in cluster names

5 participants