-
Notifications
You must be signed in to change notification settings - Fork 283
Read metrics Datasource configuration from config file #2441
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
k8s-ci-robot
merged 6 commits into
kubernetes-sigs:main
from
Mohamedma96:metrics-datasource-config-params
Mar 4, 2026
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7576d15
Read metrics Datasource configuration from config file
Mohamedma96 8b45cad
Add MetricsDataSource to values, update go.mod
Mohamedma96 5450baa
rename plugin, keep supporting command line flags for depracated flags
Mohamedma96 8470a96
revert pflag import alias
Mohamedma96 62d2fc2
Add test for config precedence, add f.Changed check to check cli flag…
Mohamedma96 68eb26f
rename factory and New method to match new naming
Mohamedma96 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
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 |
|---|---|---|
|
|
@@ -24,15 +24,23 @@ import ( | |
|
|
||
| "github.com/prometheus/common/expfmt" | ||
| "github.com/prometheus/common/model" | ||
| "github.com/spf13/pflag" | ||
| flag "github.com/spf13/pflag" | ||
|
Mohamedma96 marked this conversation as resolved.
Outdated
|
||
|
|
||
| fwkplugin "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/framework/interface/plugin" | ||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/framework/plugins/datalayer/source/http" | ||
| ) | ||
|
|
||
| const MetricsDataSourceType = "metrics-data-source" | ||
|
|
||
| // Data source configuration parameters | ||
| // Default values for the metrics data source configuration. | ||
| const ( | ||
| defaultMetricsScheme = "http" | ||
| defaultMetricsPath = "/metrics" | ||
| defaultMetricsInsecureSkipVerify = true | ||
| ) | ||
|
|
||
| // metricsDatasourceParams holds the configuration parameters for the metrics data source plugin. | ||
| // These values can be specified in the EndpointPickerConfig under the plugin's `parameters` field. | ||
| type metricsDatasourceParams struct { | ||
| // Scheme defines the protocol scheme used in metrics retrieval (e.g., "http"). | ||
| Scheme string `json:"scheme"` | ||
|
|
@@ -60,68 +68,72 @@ func MetricsDataSourceFactory(name string, parameters json.RawMessage, handle fw | |
| name, parseMetrics, PrometheusMetricType) | ||
| } | ||
|
|
||
| // Names of CLI flags in main | ||
| // These flags are registered in options.go (server package) and marked as deprecated there. | ||
| // They are kept for one release cycle to give users time to migrate their configuration | ||
| // to the EndpointPickerConfig `parameters` field (metricsDatasourceParams). | ||
| // They will be removed in a future release. | ||
| // | ||
| // TODO: | ||
| // | ||
| // 1. Consider having a cli package with all flag names and constants? | ||
| // Can't use values from runserver as this creates an import cycle with datalayer. | ||
| // Given that relevant issues/PRs have been closed so may be able to remove the cycle? | ||
| // Comment from runserver package (regarding TestPodMetricsClient *backendmetrics.FakePodMetricsClient) | ||
| // This should only be used in tests. We won't need this once we do not inject metrics in the tests. | ||
| // TODO:(https://github.com/kubernetes-sigs/gateway-api-inference-extension/issues/432) Cleanup | ||
| // | ||
| // 2. Deprecation notice on these flags being moved to the configuration file | ||
| // TODO: Remove these constants and defaultDataSourceConfigParams() once the deprecated flags | ||
| // are removed from options.go. | ||
| // Note: these flag names are duplicated here (rather than imported from the server package) | ||
| // to avoid an import cycle between the datalayer plugin and the server/runserver packages. | ||
| const ( | ||
| modelServerMetricsPathFlag = "model-server-metrics-path" | ||
| modelServerMetricsSchemeFlag = "model-server-metrics-scheme" | ||
| modelServerMetricsInsecureSkipVerifyFlag = "model-server-metrics-https-insecure-skip-verify" | ||
| ) | ||
|
|
||
| // return the default configuration state. The defaults are populated from | ||
| // existing command line flags. | ||
| // DataSource parameters values - Priority (lowest → highest): | ||
| // 1. Built-in defaults (defaultMetricsScheme / defaultMetricsPath / defaultMetricsInsecureSkipVerify) | ||
| // 2. Deprecated CLI flag value (when the flag is registered and has been set by the operator) | ||
| // 3. Explicit plugin `parameters` in EndpointPickerConfig | ||
| func defaultDataSourceConfigParams() (*metricsDatasourceParams, error) { | ||
| cfg := &metricsDatasourceParams{} | ||
| cfg := &metricsDatasourceParams{ | ||
| Scheme: defaultMetricsScheme, | ||
| Path: defaultMetricsPath, | ||
| InsecureSkipVerify: defaultMetricsInsecureSkipVerify, | ||
| } | ||
|
|
||
| scheme, err := fromStringFlag(modelServerMetricsSchemeFlag) | ||
| if err != nil { | ||
| return nil, err | ||
| if scheme, ok := fromStringFlag(modelServerMetricsSchemeFlag); ok { | ||
| cfg.Scheme = scheme | ||
| } | ||
| cfg.Scheme = scheme | ||
|
|
||
| path, err := fromStringFlag(modelServerMetricsPathFlag) | ||
| if err != nil { | ||
| return nil, err | ||
| if path, ok := fromStringFlag(modelServerMetricsPathFlag); ok { | ||
| cfg.Path = path | ||
| } | ||
| cfg.Path = path | ||
|
|
||
| insecure, err := fromBoolFlag(modelServerMetricsInsecureSkipVerifyFlag) | ||
| if err != nil { | ||
| if insecure, ok, err := fromBoolFlag(modelServerMetricsInsecureSkipVerifyFlag); err != nil { | ||
| return nil, err | ||
| } else if ok { | ||
| cfg.InsecureSkipVerify = insecure | ||
| } | ||
| cfg.InsecureSkipVerify = insecure | ||
|
|
||
| return cfg, nil | ||
| } | ||
|
|
||
| func fromStringFlag(name string) (string, error) { | ||
| f := pflag.Lookup(name) | ||
| // fromStringFlag returns the value of a registered pflag string flag. | ||
| // The second return value is false when the flag is not registered; no error is returned in that case. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: comment should be changed to reflect
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| func fromStringFlag(name string) (string, bool) { | ||
| f := flag.Lookup(name) | ||
| if f == nil { | ||
| return "", fmt.Errorf("flag not found: %s", name) | ||
| return "", false | ||
| } | ||
| return f.Value.String(), nil | ||
| return f.Value.String(), true | ||
| } | ||
|
|
||
| func fromBoolFlag(name string) (bool, error) { | ||
| f := pflag.Lookup(name) | ||
| // fromBoolFlag returns the value of a registered pflag bool flag. | ||
| // The second return value is false when the flag is not registered; no error is returned in that case. | ||
| // An error is returned only when the flag exists but its value cannot be parsed as a bool. | ||
| func fromBoolFlag(name string) (bool, bool, error) { | ||
| f := flag.Lookup(name) | ||
| if f == nil { | ||
| return false, fmt.Errorf("flag not found: %s", name) | ||
| return false, false, nil | ||
| } | ||
| b, err := strconv.ParseBool(f.Value.String()) | ||
| if err != nil { | ||
| return false, fmt.Errorf("invalid bool flag %q: %w", name, err) | ||
| return false, false, fmt.Errorf("invalid bool flag %q: %w", name, err) | ||
| } | ||
| return b, nil | ||
| return b, true, nil | ||
| } | ||
|
|
||
| func parseMetrics(data io.Reader) (any, error) { | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this got reverted already