-
Notifications
You must be signed in to change notification settings - Fork 875
Add per-plugin workload counters #13278
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a36b73c
Add per-plugin workload counters
moonchen e02f904
test_proxy: drop redundant IpAllow::subjects stub
moonchen c816f36
test: scope plugin metric checks to the plugins' own namespace
moonchen a6ab8ac
PluginVC: count a transfer only when data is actually moved
moonchen 714abbb
PluginDso: make registerPluginMetrics header-inline
moonchen becf659
PluginThreadContext: move into ts::proxy in its own file
moonchen 4042653
test: reorganize per_plugin_metrics as a test class
moonchen a033680
test: gate per_plugin_metrics on its plugins
moonchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /** @file | ||
|
|
||
| Per-plugin identity carried on the continuations a plugin creates. | ||
|
|
||
| @section license License | ||
|
|
||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <string> | ||
| #include <string_view> | ||
|
|
||
| #include "tscore/Ptr.h" | ||
| #include "tsutil/Metrics.h" | ||
|
|
||
| /** Carries a plugin's identity on the continuations it creates so that | ||
| * proxy.process.plugin.<name>.* workload counters can be attributed back to the originating | ||
| * plugin DSO. | ||
| * | ||
| * This lives in ts::proxy rather than ts::http_remap because it is shared by both remap plugins | ||
| * (PluginDso) and global plugins (GlobalPluginContext, in Plugin.cc). The library dependency only | ||
| * runs ts::http_remap -> ts::proxy, so putting it here lets both paths resolve these symbols. */ | ||
| class PluginThreadContext : public RefCountObjInHeap | ||
| { | ||
| public: | ||
| virtual void acquire() = 0; | ||
| virtual void release() = 0; | ||
|
|
||
| /** Register this plugin's proxy.process.plugin.<name>.* metrics. @a plugin_name is the DSO path; | ||
| * only its basename stem (extension removed) is used as <name>. */ | ||
| void registerPluginMetrics(std::string_view plugin_name); | ||
|
|
||
| void countInvocation(); | ||
|
|
||
| ts::Metrics::Counter::AtomicType *_invocations = nullptr; | ||
| ts::Metrics::Counter::AtomicType *_bytes = nullptr; | ||
| ts::Metrics::Counter::AtomicType *_transfers = nullptr; | ||
|
|
||
| static constexpr const char *const _tag = "plugin_context"; /** @brief log tag used by this class */ | ||
|
|
||
| private: | ||
| /** Derive a metric-safe token from a plugin path: the basename with the extension removed, then any | ||
| * character outside [A-Za-z0-9_-] replaced by '_' (e.g. "/.../header_rewrite.so" -> "header_rewrite"). */ | ||
| static std::string _metric_token(std::string_view name); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /** @file | ||
|
|
||
| Per-plugin identity carried on the continuations a plugin creates. | ||
|
|
||
| @section license License | ||
|
|
||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| #include "proxy/PluginThreadContext.h" | ||
|
|
||
| #include <algorithm> | ||
| #include <cctype> | ||
| #include <string> | ||
| #include <string_view> | ||
|
|
||
| void | ||
| PluginThreadContext::registerPluginMetrics(std::string_view plugin_name) | ||
| { | ||
| std::string prefix = "proxy.process.plugin." + _metric_token(plugin_name) + "."; | ||
|
|
||
| _invocations = ts::Metrics::Counter::createPtr(prefix + "invocations"); | ||
| _bytes = ts::Metrics::Counter::createPtr(prefix + "bytes"); | ||
| _transfers = ts::Metrics::Counter::createPtr(prefix + "transfers"); | ||
| } | ||
|
|
||
| void | ||
| PluginThreadContext::countInvocation() | ||
| { | ||
| if (_invocations != nullptr) { | ||
| _invocations->increment(1); | ||
| } | ||
| } | ||
|
|
||
| std::string | ||
| PluginThreadContext::_metric_token(std::string_view name) | ||
| { | ||
| if (auto slash = name.find_last_of('/'); slash != std::string_view::npos) { | ||
| name.remove_prefix(slash + 1); | ||
| } | ||
| if (auto dot = name.find_last_of('.'); dot != std::string_view::npos) { | ||
| name = name.substr(0, dot); | ||
| } | ||
|
|
||
| std::string token{name}; | ||
| std::replace_if(token.begin(), token.end(), [](unsigned char c) { return !(std::isalnum(c) || c == '_' || c == '-'); }, '_'); | ||
| if (token.empty()) { | ||
| token = "unknown"; | ||
| } | ||
| return token; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,5 +22,3 @@ | |
| */ | ||
|
|
||
| #include "proxy/IPAllow.h" | ||
|
|
||
| uint8_t IpAllow::subjects[IpAllow::Subject::MAX_SUBJECTS]; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.