Skip to content

stats: add per network filter chain scope - #17765

Closed
lambdai wants to merge 3 commits into
envoyproxy:mainfrom
lambdai:perfcscope
Closed

lambdai wants to merge 3 commits into
envoyproxy:mainfrom
lambdai:perfcscope

Conversation

@lambdai

@lambdai lambdai commented Aug 18, 2021

Copy link
Copy Markdown
Contributor

Commit Message:
Create the stats scope for each filter chain factory context.
Add a leafScope() into FactoryContext interace to return the above conditionally.

#17690 Fix 1 of 2
Signed-off-by: Yuchen Dai [email protected]

Additional Description:
Alternatively, I can addd filterChainScope() but not all the factory context impl has filter chain scope. Some factory contexts were designed to build listener filter chain only.

If this is the right direction, I can go through the listenerScope() usage to switch to the new scope.

Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Deprecated:]
[Optional API Considerations:]

@lambdai

lambdai commented Aug 19, 2021

Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #17765 (comment) was created by @lambdai.

see: more, trace.

@dmitri-d

Copy link
Copy Markdown
Contributor

Is the idea to have a tree of stat scopes where parent stats will also return stats of all its currently alive children?

CI failures should resolve If you merge the changes in main.

@lambdai

lambdai commented Aug 20, 2021

Copy link
Copy Markdown
Contributor Author

Is the idea to have a tree of stat scopes where parent stats will also return stats of all its currently alive children?

That's interesting. I have no idea of this topic. It stays what they were.

The background is that the stats create in the scope is destroyed when the scope is destroyed.

There are stats attached to the scope that stay alive much longer than the stats should. And the API for the stat itself to select its desired scope.

This PR is introducing a new per-filter-chain scope which is shorter than the its owner listener scope.

CI failures should resolve If you merge the changes in main.

Thanks! merged

* is the smallest scope to accommodate the per filter stats. Use listenerScope() or scope() if
* longer life time is needed.
*/
virtual Stats::Scope& leafScope() PURE;

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.

Is there a need for access to a different scope? I haven't looked at the details, but I think it may be better to pass a different factory_context to filters, where the scope() returned is the correct one for that filter-chain, instead of giving them access to both and hoping they pick the correct one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Somewhat related: I found it was hard for me to figure out what the current scope is; I know what it should be, but I had to check the call sites to verify it was indeed correct. @ggreenway's suggestion sounds great in that context.

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.

@ggreenway

  1. scope() is currently referred to "global scope". My hunch is that it's not worth a renaming or change the semantic.
  2. Upper scopes are desired, we do have
    a. listenerScope() called by HCM and other network filters
    b. global stats(e.g. a RDS config stat that created by a HCM config but shared by the HCMs outside this listener).

So barely one scope() might not work. Are you saying we pass two context, filter-chain-factory-context + listener-factory-context instead of a "factory-context"? That should work, at the cost that touching each network filter, maybe sub filters such as http/thrift...

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.

It seems like any scope accessible to the filter should have a lifetime that ends when the filterchain is removed.

I think we can leave all interfaces the same, and in PerFilterChainFactoryContextImpl, create new scopes for both scope() and listenerScope(). The factory will own these new scopes, and only the newly created scopes (not the parent scopes) can be accessed via that factorycontext (which is all the filter gets).

cc @jmarantz @mattklein123 can you double-check that my statements/suggestions are correct?

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.

That's interesting. So the global scope and listener scope life is shorter than it declared as "global" and "listener" correspondingly, am I understanding it correctly?

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.

scope() is not truly global, I don't think. It has no prefix, but I think it is lifetime'd to the listener currently. See

global_scope_(server.stats().createScope("")),
for where it is created. I think we create another sub-scope for the filter-chain. We want any stats created by the filter to be removed when the owning filter-chain is removed.

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.

Yeah that makes more sense, I think it's just about the prefix or not. I think just changing listenerScope() in the filter chain factory to be per filter chain is the correct fix.

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.

Got it. I will create another PR with the new listenerScope() impl in filter chain factory context

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.

No, I think both scope() and listenerScope() need to be per filter chain. Otherwise stats not namespaced under the listener will have the wrong lifetime.

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.

Sorry yes I think ^ is correct, however as I said previously we probably still have to have a listener scoped one and use that for internal listener stats as well as listener filter stats, so you might need to spit the contexts if not already split.

@lambdai

lambdai commented Aug 31, 2021

Copy link
Copy Markdown
Contributor Author

Close this one in favor of #17931

@lambdai lambdai closed this Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants