-
Notifications
You must be signed in to change notification settings - Fork 213
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
Fix the fallback for container metrics logic to query both container and pod metrics #789
Open
nabil-dbz
wants to merge
4
commits into
GoogleCloudPlatform:master
Choose a base branch
from
nabil-dbz:container-custom-metrics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fbfa0e7
Use one_of operator for the fallback for container metrics logic
nabil-dbz a6e7f58
Add resource.labels to the allowlist of prefixes for custom metrics
nabil-dbz d25ecd2
Add ContainerType in addition to PodContainerType
nabil-dbz f85193b
Allow the label resource.labels.container_name instead of all labels …
nabil-dbz 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 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 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 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 |
---|---|---|
|
@@ -41,7 +41,7 @@ var ( | |
allowedExternalMetricsFullLabelNames = []string{"resource.type", "reducer"} | ||
// allowedCustomMetricsLabelPrefixes and allowedCustomMetricsFullLabelNames specify all metric labels allowed for querying | ||
allowedCustomMetricsLabelPrefixes = []string{"metric.labels"} | ||
allowedCustomMetricsFullLabelNames = []string{"reducer"} | ||
allowedCustomMetricsFullLabelNames = []string{"resource.labels.container_name", "reducer"} | ||
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. I think you can omit |
||
allowedReducers = map[string]bool{ | ||
"REDUCE_NONE": true, | ||
"REDUCE_MEAN": true, | ||
|
@@ -169,15 +169,16 @@ func (nc nodeValues) getNodeNames() []string { | |
// | ||
// use NewQueryBuilder() to initialize | ||
type QueryBuilder struct { | ||
translator *Translator // translator provides configurations to filter | ||
metricName string // metricName is the metric name to filter | ||
metricKind string // metricKind is the metric kind to filter | ||
metricValueType string // metricValueType is the metric value type to filter | ||
metricSelector labels.Selector // metricSelector is the metric selector to filtere | ||
namespace string // namespace is the namespace to filter (mutually exclusive with nodes) | ||
pods podValues // pods is the pods to filter (mutually exclusive with nodes) | ||
nodes nodeValues // nodes is the nodes to filter (mutually exclusive with namespace, pods) | ||
enforceContainerType bool // enforceContainerType decides whether to enforce using container type filter schema | ||
translator *Translator // translator provides configurations to filter | ||
metricName string // metricName is the metric name to filter | ||
metricKind string // metricKind is the metric kind to filter | ||
metricValueType string // metricValueType is the metric value type to filter | ||
metricSelector labels.Selector // metricSelector is the metric selector to filtere | ||
namespace string // namespace is the namespace to filter (mutually exclusive with nodes) | ||
pods podValues // pods is the pods to filter (mutually exclusive with nodes) | ||
nodes nodeValues // nodes is the nodes to filter (mutually exclusive with namespace, pods) | ||
enforceContainerType bool // enforceContainerType decides whether to enforce using container type filter schema | ||
enforcePodContainerType bool // enforcePodContainerType decides wether to to enforce using pod_container type filter schema | ||
} | ||
|
||
// NewQueryBuilder is the initiator for QueryBuilder | ||
|
@@ -314,14 +315,22 @@ func (qb QueryBuilder) getResourceNames() []string { | |
return qb.pods.getPodIDs() | ||
} | ||
|
||
// AsContainerType enforces to query k8s_container type metrics | ||
// EnforceContainerType enforces to query k8s_container type metrics | ||
// | ||
// it it valid only when useNewResourceModel is true | ||
func (qb QueryBuilder) AsContainerType() QueryBuilder { | ||
func (qb QueryBuilder) EnforceContainerType() QueryBuilder { | ||
qb.enforceContainerType = true | ||
return qb | ||
} | ||
|
||
// EnforcePodContainerType enforces to query both k8s_pod and k8s_container type metrics | ||
// | ||
// it it valid only when useNewResourceModel is true | ||
func (qb QueryBuilder) EnforcePodContainerType() QueryBuilder { | ||
qb.enforcePodContainerType = true | ||
return qb | ||
} | ||
|
||
// validate is an internal helper function for checking prerequisits before Build | ||
// | ||
// Criteria: | ||
|
@@ -366,7 +375,7 @@ func (qb QueryBuilder) validate() error { | |
return apierr.NewBadRequest("distributions are not supported") | ||
} | ||
|
||
if qb.enforceContainerType && !qb.translator.useNewResourceModel { | ||
if !qb.translator.useNewResourceModel && (qb.enforceContainerType || qb.enforcePodContainerType) { | ||
return apierr.NewInternalError(fmt.Errorf("illegal state! Container metrics works only with new resource model")) | ||
} | ||
|
||
|
@@ -392,6 +401,11 @@ func (qb QueryBuilder) getFilterBuilder() utils.FilterBuilder { | |
return utils.NewFilterBuilder(utils.SchemaTypes[utils.ContainerSchemaKey]) | ||
} | ||
|
||
// pod_container type FilterBuilder | ||
if qb.enforcePodContainerType { | ||
return utils.NewFilterBuilder(utils.SchemaTypes[utils.PodContainerSchemaKey]) | ||
} | ||
|
||
// prometheus type FilterBuilder | ||
if strings.HasPrefix(qb.metricName, PrometheusMetricPrefix) { | ||
return utils.NewFilterBuilder(utils.SchemaTypes[utils.PrometheusSchemaKey]) | ||
|
Oops, something went wrong.
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.
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.
We should really document what this does because modifying a response object here could be really confusing.
I was initially going to suggest not returning a ListTimeSeriesResponse here but I see that this would cause a bunch of issues with the follow-up calls.