Skip to content

stats: add utilities to create stats from a vector of tokens, mixing dynamic and symbolic elements.#10735

Merged
jmarantz merged 24 commits intoenvoyproxy:masterfrom
jmarantz:counter-from-vector
Apr 25, 2020
Merged

stats: add utilities to create stats from a vector of tokens, mixing dynamic and symbolic elements.#10735
jmarantz merged 24 commits intoenvoyproxy:masterfrom
jmarantz:counter-from-vector

Conversation

@jmarantz
Copy link
Copy Markdown
Contributor

@jmarantz jmarantz commented Apr 10, 2020

Description: Creating joined stat names is a bit awkward due to the way the memory management needs to work, and having dynamic components to the name adds further complexity. This PR adds some utility helper methods to make this much easier and terse to express.

There's one subtle semantic change in the grpc status, which is to use a Dynamic stat name rather than building a locally controlled mutex-protected map from strings to symbolic stat names.

Risk Level: low -- this is mostly a refactoring
Testing: //test/...
Docs Changes: n/a
Release Notes: n/a

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
@jmarantz
Copy link
Copy Markdown
Contributor Author

jmarantz commented Apr 10, 2020

@snowp @mattklein123 @danzh2010 ptal

Snow/Matt: curious what you think about this pattern of putting this helper function in Stats::Utility rather than making it a method of Scope. The downside is it's more cumbersome as a static method at call-sites. The upside is that there are several derivations of Scope and it's annoying to have to duplicate the code. I think Snow ran into this too.

One alternative which I've used a lot in the past, but is less common in Envoy, is to have a shared helper class between the interface and the implementations with common methods factored out there.

The other question is whether we should discourage extensive use of dynamic StatNames as they are more expensive, and you could argue this makes it too easy. Curious to hear your thoughts.

If I do go through with this, there are about 15 or so more places in the code where we could do some simplifications of creating stats based on this. Wouldn't all need to get done at once though.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
…ollision?

Signed-off-by: Joshua Marantz <jmarantz@google.com>
@mattklein123 mattklein123 self-assigned this Apr 13, 2020
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

At a high level this looks like a good improvement to me!

/wait

@snowp
Copy link
Copy Markdown
Contributor

snowp commented Apr 14, 2020

I agree that this is an improvement, I think we can document the pitfalls of using dynamic names instead of complicating the API intentionally.

I think any attempt to make this more explicit (e.g. no implicit cast from string_view) still makes it easy to mess up unless docs are consulted - unless we make it kinda ridiculous scary sounding, e.g. ,

Utility::counterFromElements(scope, {prefix_, DynamicStatDangerReadDocs(dynamic_value)}, tags);

which I don't think is worth it

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
…sed to new util functions.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
@jmarantz
Copy link
Copy Markdown
Contributor Author

I pushed a version where it's not quite as verbose as what @snowp suggested, but I did add a type-wrapper so you have to use Stats::Utility::Dynamic(str) when you want to compose a joined stat-name that includes a dynamic string. Otherwise i think it won't be at all clear at the call-sites that dynamics are being added.

Still working on cleaning up the other non-test uses of join().

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
…ments.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
…*FromElements."

This reverts commit 85b57ed.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
…mentation.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
@jmarantz jmarantz changed the title WiP stats: add utilities to create stats from a vector of tokens, mixing dynamic and symbolic elements. stats: add utilities to create stats from a vector of tokens, mixing dynamic and symbolic elements. Apr 23, 2020
@jmarantz jmarantz marked this pull request as ready for review April 23, 2020 11:58
@jmarantz
Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s), but failed to run 2 pipeline(s).

@jmarantz
Copy link
Copy Markdown
Contributor Author

This is ready for review; thanks!

snowp
snowp previously requested changes Apr 24, 2020
Copy link
Copy Markdown
Contributor

@snowp snowp 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 a massive improvement IMO, thanks for doing this! A couple comments

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks this is a great improvement. One small perf suggestion.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
mattklein123
mattklein123 previously approved these changes Apr 24, 2020
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks!

Signed-off-by: Joshua Marantz <jmarantz@google.com>
…s. The latter didn't work for alll call-sites.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
@jmarantz
Copy link
Copy Markdown
Contributor Author

I need another review due to a commit (969c26a) to undo a suggestion about how to write the constructor, which apparently did not work at some call-site that I didn't manually re-test.

@jmarantz jmarantz dismissed snowp’s stale review April 25, 2020 14:03

Addressed all comments.

@jmarantz jmarantz merged commit a7f411c into envoyproxy:master Apr 25, 2020
@jmarantz jmarantz deleted the counter-from-vector branch April 25, 2020 14:04
@jmarantz jmarantz mentioned this pull request Apr 25, 2020
spenceral added a commit to spenceral/envoy that referenced this pull request Apr 27, 2020
Signed-off-by: Spencer Lewis <slewis@squareup.com>

* master:
  fault injection: add support for setting gRPC status (envoyproxy#10841)
  tests: tag tests that fail on Windows with fails_on_windows (envoyproxy#10940)
  Fix typo on Postgres Proxy documentation. (envoyproxy#10930)
  fuzz: improve header/data stop/continue modeling in HCM fuzzer. (envoyproxy#10931)
  gzip filter: allow setting zlib compressor's chunk size (envoyproxy#10508)
  http: replace vector/reserve with InlinedVector in codec helper (envoyproxy#10941)
  stats: add utilities to create stats from a vector of tokens, mixing dynamic and symbolic elements. (envoyproxy#10735)
  hcm: avoid invoking 100-continue handling on decode filter. (envoyproxy#10929)
  prometheus stats: Correctly group lines of the same metric name. (envoyproxy#10833)
  status: Fix ASAN error in Status payload handling (envoyproxy#10906)
  path: Fix merge slash for paths ending with slash and present query args (envoyproxy#10922)
  compressor filter: add benchmark (envoyproxy#10464)
  xray: expected_span_name is not captured by the lambda with MSVC (envoyproxy#10934)
  ci: update before purge in cleanup (envoyproxy#10938)
  tracer: Improve test coverage for x-ray (envoyproxy#10890)
  Revert "init: order dynamic resource initialization to make RTDS always be first (envoyproxy#10362)" (envoyproxy#10919)
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.

3 participants