Skip to content
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

NETOBSERV-1447: Added a check to log a warning if some labels are used in metric defi… #629

Merged
merged 1 commit into from May 14, 2024

Conversation

OlivierCazade
Copy link
Contributor

Description

Added a check to log a warning if some labels are used in metric definition

Dependencies

n/a

Checklist

If you are not familiar with our processes or don't know what to answer in the list below, let us know in a comment: the maintainers will take care of that.

  • Is this PR backed with a JIRA ticket? If so, make sure it is written as a title prefix (in general, PRs affecting the NetObserv/Network Observability product should be backed with a JIRA ticket - especially if they bring user facing changes).
  • Does this PR require product documentation?
    • If so, make sure the JIRA epic is labelled with "documentation" and provides a description relevant for doc writers, such as use cases or scenarios. Any required step to activate or configure the feature should be documented there, such as new CRD knobs.
  • Does this PR require a product release notes entry?
    • If so, fill in "Release Note Text" in the JIRA.
  • Is there anything else the QE team should know before testing? E.g: configuration changes, environment setup, etc.
    • If so, make sure it is described in the JIRA ticket.
  • QE requirements (check 1 from the list):
    • Standard QE validation, with pre-merge tests unless stated otherwise.
    • Regression tests only (e.g. refactoring with no user-facing change).
    • No QE (e.g. trivial change with high reviewer's confidence, or per agreement with the QE team).

@OlivierCazade
Copy link
Contributor Author

/retest

@codecov-commenter
Copy link

codecov-commenter commented May 7, 2024

Codecov Report

Attention: Patch coverage is 69.23077% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 67.00%. Comparing base (e19e733) to head (f7f1fae).
Report is 2 commits behind head on main.

Files Patch % Lines
apis/flowmetrics/v1alpha1/flowmetric_webhook.go 50.00% 2 Missing and 1 partial ⚠️
pkg/helper/helpers.go 70.00% 2 Missing and 1 partial ⚠️
controllers/consoleplugin/config/config.go 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #629      +/-   ##
==========================================
- Coverage   67.01%   67.00%   -0.02%     
==========================================
  Files          68       68              
  Lines        7783     7804      +21     
==========================================
+ Hits         5216     5229      +13     
- Misses       2192     2197       +5     
- Partials      375      378       +3     
Flag Coverage Δ
unittests 67.00% <69.23%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@msherif1234
Copy link
Contributor

/lgtm

@memodi
Copy link
Contributor

memodi commented May 7, 2024

building cluster with this change for testing.

@memodi
Copy link
Contributor

memodi commented May 7, 2024

I was able to see warning in Operator logs:

2024-05-07T16:47:43.402Z	INFO	flowmetric-resource	Warning: metric label has high cardinality, please limit it by using some filters	{"labelName": "DstAddr"}

I have some feedback for this warning to be more visible, we can have this PR merged.

/label qe-approved

@openshift-ci openshift-ci bot added the qe-approved QE has approved this pull request label May 7, 2024
@jotak jotak changed the title NETOBSERV-1447 : Added a check to log a warning if some labels are used in metric defi… NETOBSERV-1447: Added a check to log a warning if some labels are used in metric defi… May 10, 2024
@openshift-ci-robot
Copy link
Collaborator

openshift-ci-robot commented May 10, 2024

@OlivierCazade: This pull request references NETOBSERV-1447 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.16.0" version, but no target version was set.

In response to this:

Description

Added a check to log a warning if some labels are used in metric definition

Dependencies

n/a

Checklist

If you are not familiar with our processes or don't know what to answer in the list below, let us know in a comment: the maintainers will take care of that.

  • Is this PR backed with a JIRA ticket? If so, make sure it is written as a title prefix (in general, PRs affecting the NetObserv/Network Observability product should be backed with a JIRA ticket - especially if they bring user facing changes).
  • Does this PR require product documentation?
  • If so, make sure the JIRA epic is labelled with "documentation" and provides a description relevant for doc writers, such as use cases or scenarios. Any required step to activate or configure the feature should be documented there, such as new CRD knobs.
  • Does this PR require a product release notes entry?
  • If so, fill in "Release Note Text" in the JIRA.
  • Is there anything else the QE team should know before testing? E.g: configuration changes, environment setup, etc.
  • If so, make sure it is described in the JIRA ticket.
  • QE requirements (check 1 from the list):
  • Standard QE validation, with pre-merge tests unless stated otherwise.
  • Regression tests only (e.g. refactoring with no user-facing change).
  • No QE (e.g. trivial change with high reviewer's confidence, or per agreement with the QE team).

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.


func LabelIsHighCardinality(label string) bool {
pluginCfg := config.PluginConfig{}
err := yaml.Unmarshal(config.LoadStaticFrontendConfig(), &pluginCfg.Frontend)
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to cache the PluginConfig rather than unmarshaling it every time (not just here but also done in other places). Especially here that's done in a for loop for each label

Copy link
Contributor

Choose a reason for hiding this comment

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

we could leverage https://github.com/netobserv/network-observability-operator/blob/main/pkg/helper/helpers.go#L95 remove the for loop and pass in another bool isHighCardinality or do something similar and this will do unmarshall once WDYT?

something like

func FindFilter(labels []string, isNumber, isHighCardinality bool) bool {
	var cfg config.FrontendConfig
	type filter struct {
		exists            bool
		isNum             bool
		isHighCardinality bool
	}

	err := yaml.Unmarshal(config.LoadStaticFrontendConfig(), &cfg)
	if err != nil {
		return false
	}

	labelMap := make(map[string]filter)

	for _, f := range cfg.Fields {
		value := filter{
			exists:            true,
			isNum:             f.Type == "number",
			isHighCardinality: f.CardinalityWarn == config.CardinalityWarnCareful || f.CardinalityWarn == config.CardinalityWarnAvoid,
		}
		labelMap[f.Name] = value
	}

	for _, l := range labels {
		if ok := labelMap[l].exists; !ok {
			return false
		}
		if isNumber && !labelMap[l].isNum {
			return false
		}
		if isHighCardinality && labelMap[l].isHighCardinality {
			return true
		}
	}

	return true
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I modified LoadStaticFrontendConfig to unmarshall inside the function and only once.

cfgLabel.CardinalityWarn == config.CardinalityWarnAvoid
}
}
return false
Copy link
Contributor

Choose a reason for hiding this comment

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

this works for me thank you!!

@msherif1234
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm label May 13, 2024
@OlivierCazade
Copy link
Contributor Author

/approve

Copy link

openshift-ci bot commented May 14, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: OlivierCazade

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit 8d0f97a into netobserv:main May 14, 2024
10 checks passed
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.

None yet

6 participants