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

Hubble: Adding structured format to configure Hubble Metrics #32294

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vakalapa
Copy link
Contributor

@vakalapa vakalapa commented May 1, 2024

Draft PR for intial changes to bring structured format to static string-based metrics enablement.

First PR in the series to implement, https://github.com/cilium/design-cfps/blob/main/cilium/CFP-30788-managing-hubble-metrics-cardinality.md

CFP: cilium/design-cfps#29

Todo:
2) Adding tests to the new structures
 
Please ensure your pull request adheres to the following guidelines:

  • For first time contributors, read Submitting a pull request
  • All code is covered by unit and/or runtime tests where feasible.
  • All commits contain a well written commit description including a title,
    description and a Fixes: #XXX line if the commit addresses a particular
    GitHub issue.
  • If your commit description contains a Fixes: <commit-id> tag, then
    please add the commit author[s] as reviewer[s] to this issue.
  • All commits are signed off. See the section Developer’s Certificate of Origin
  • Provide a title or release-note blurb suitable for the release notes.
  • Are you a user of Cilium? Please add yourself to the Users doc
  • Thanks for contributing!

Fixes: #30788

<!-- Enter the release note text here if needed or remove this section! -->

@maintainer-s-little-helper
Copy link

Commit 714df89 does not match "(?m)^Signed-off-by:".

Please follow instructions provided in https://docs.cilium.io/en/stable/contributing/development/contributing_guide/#developer-s-certificate-of-origin

@maintainer-s-little-helper maintainer-s-little-helper bot added dont-merge/needs-sign-off The author needs to add signoff to their commits before merge. dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. labels May 1, 2024
@vakalapa vakalapa force-pushed the vakalapa/structuredctxopts branch from 43aa546 to 7620ed6 Compare May 1, 2024 22:33
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-sign-off The author needs to add signoff to their commits before merge. label May 1, 2024

// DynamicMetricsConfig represents the structure used for configuring
// Hubble metrics context options
type DynamicMetricsConfig struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chancez Can you help pre-review these structures before i start making more changes.

}
} else {
// temporarily handling comma separated values for labels context
for _, option := range strings.Split(s, ",") {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chancez this is a weird case, Hubble uses two kinds of delimiters "|" for the contextOptions and "," for labelcontexts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that's because we needed another delimiter for nested config within the already nested config.

@vakalapa vakalapa force-pushed the vakalapa/structuredctxopts branch from 857b203 to 647d81c Compare May 1, 2024 23:43
@vakalapa vakalapa force-pushed the vakalapa/structuredctxopts branch from 647d81c to decee4b Compare May 1, 2024 23:57
Values ContextValues `json:"values,omitempty" yaml:"values,omitempty"`
}

type ContextOptionConfigs []*ContextOptionConfig
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Want to group the non-struct types together?


type ContextOptionConfigs []*ContextOptionConfig

type MetricConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Exported struct needs comment for documentation?

Copy link
Contributor

Choose a reason for hiding this comment

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

And some comments on the individual fields too

Metrics []*MetricConfig `json:"metrics,omitempty" yaml:"metrics,omitempty"`
}

func (d *DynamicMetricsConfig) GetMetricNames() map[string]struct{} {
Copy link
Contributor

Choose a reason for hiding this comment

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

GetMetricNames -> MetricNames

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, why return a map? The function name suggests getting a list.

return metrics
}

func ParseStaticMetricsConfig(enabledMetrics []string) (metricConfigs *DynamicMetricsConfig) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can we add an example of what an enabledMetric may possibly look like?

type ContextValues []string

// ContextOptions is a structure used for configuring Hubble metrics context options
type ContextOptionConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could also name this ContextOptions? Since that's the name in the ConfigMap's yaml, and it looks like there used to be a type with similar name:

Init(registry *prometheus.Registry, options Options)

@@ -25,15 +25,15 @@ type dnsHandler struct {
responseTypes *prometheus.CounterVec
}

func (d *dnsHandler) Init(registry *prometheus.Registry, options api.Options) error {
c, err := api.ParseContextOptions(options)
func (d *dnsHandler) Init(registry *prometheus.Registry, options *api.MetricConfig) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: rename all the args that used to be options api.Options?


// DynamicMetricsConfig represents the structure used for configuring
// Hubble metrics context options
type DynamicMetricsConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

naming idea: ConfiguredMetrics?

@@ -0,0 +1,26 @@
hubbleMetrics:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this file used anywhere yet?

@@ -146,3 +128,101 @@ var registry = NewRegistry(
func DefaultRegistry() *Registry {
return registry
}

// FlowFilters is a slice of filters to include or exclude flows.
type FlowFilters []*pb.FlowFilter
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't feel necessary to introduce another type here.

Values ContextValues `json:"values,omitempty" yaml:"values,omitempty"`
}

type ContextOptionConfigs []*ContextOptionConfig
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure you need a type here, can just use []*ContextOptionConfig where needed.

Copy link
Contributor

@chancez chancez left a comment

Choose a reason for hiding this comment

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

Generally this looks pretty good to me. My only thought is we're kinda lacking on tests that actually deploy Hubble with metrics enabled so it's hard to feel confident in a bigger change like this not resulting in any regressions.

I'm not sure about the best approach to remedy that though. My current thinking is it might be wise to add enable metrics in our default helm values for CI (in .github/actions/helm-default/action.yaml or ci-required-values.yaml). That would need to be done in a separate PR though, since the changes will be ignored until they get merged into main.

Copy link

github-actions bot commented Jun 6, 2024

This pull request has been automatically marked as stale because it
has not had recent activity. It will be closed if no further activity
occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale The stale bot thinks this issue is old. Add "pinned" label to prevent this from becoming stale. label Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. stale The stale bot thinks this issue is old. Add "pinned" label to prevent this from becoming stale.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CFP: Hubble Label to exclude namespaces/pods from metrics
4 participants