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

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

Merged
merged 7 commits into from
Oct 4, 2017

Conversation

hennna
Copy link
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 [email protected]

"#/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
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
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
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 <[email protected]>
@@ -31,7 +31,7 @@ Cluster
name
*(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
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.

@@ -81,7 +87,7 @@ ClusterInfoImpl::ClusterInfoImpl(const envoy::api::v2::Cluster& config,
std::chrono::milliseconds(PROTOBUF_GET_MS_REQUIRED(config, connect_timeout))),
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
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
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
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 <[email protected]>
@hennna hennna changed the title Replace ':' with '_' in stats cluster name. Replace ':' with '_' in stats name. Oct 4, 2017
Copy link
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
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
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
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 <[email protected]>
Signed-off-by: Henna Huang <[email protected]>
@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
htuch added a commit to envoyproxy/data-plane-api that referenced this pull request Oct 30, 2017
@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 <[email protected]>
Signed-off-by: JP Simard <[email protected]>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Signed-off-by: Mike Schore <[email protected]>
Signed-off-by: JP Simard <[email protected]>
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