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-1500 : Refactoring of transform network API #580

Merged

Conversation

OlivierCazade
Copy link
Contributor

@OlivierCazade OlivierCazade commented Feb 1, 2024

Description

Created different type for the different transform rules

Previously the NetworkTransformRule had all fields at the same level, but they were not all used by all transform network types and the Parameter field was used differently depending on the type.

The struct go from this:

type NetworkTransformRule struct {
	Input           string        `yaml:"input,omitempty" json:"input,omitempty" doc:"entry input field"`
	Output          string        `yaml:"output,omitempty" json:"output,omitempty" doc:"entry output field"`
	Type            string        `yaml:"type,omitempty" json:"type,omitempty" enum:"TransformNetworkOperationEnum" doc:"one of the following:"`
	Parameters      string        `yaml:"parameters,omitempty" json:"parameters,omitempty" doc:"parameters specific to type"`
	Assignee        string        `yaml:"assignee,omitempty" json:"assignee,omitempty" doc:"value needs to assign to output field"`
	KubernetesInfra *K8sInfraRule `yaml:"kubernetes_infra,omitempty" json:"kubernetes_infra,omitempty" doc:"Kubernetes infra rule specific configuration"`
	Kubernetes      *K8sRule      `yaml:"kubernetes,omitempty" json:"kubernetes,omitempty" doc:"Kubernetes rule specific configuration"`
}

To this :


type NetworkTransformRule struct {
	Type            string                 `yaml:"type,omitempty" json:"type,omitempty" enum:"TransformNetworkOperationEnum" doc:"one of the following:"`
	KubernetesInfra *K8sInfraRule          `yaml:"kubernetes_infra,omitempty" json:"kubernetes_infra,omitempty" doc:"Kubernetes infra rule configuration"`
	Kubernetes      *K8sRule               `yaml:"kubernetes,omitempty" json:"kubernetes,omitempty" doc:"Kubernetes rule configuration"`
	AddSubnet       *NetworkAddSubnetRule  `yaml:"add_subnet,omitempty" json:"add_subnet,omitempty" doc:"Add subnet rule configuration"`
	AddLocation     *NetworkGenericRule    `yaml:"add_location,omitempty" json:"add_location,omitempty" doc:"Add location rule configuration"`
	AddIPCategory   *NetworkGenericRule    `yaml:"add_ip_category,omitempty" json:"add_ip_category,omitempty" doc:"Add ip category rule configuration"`
	AddService      *NetworkAddServiceRule `yaml:"add_service,omitempty" json:"add_service,omitempty" doc:"Add service rule configuration"`
}

Now every rule type has its own structure.

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.

  • Will this change affect NetObserv / Network Observability operator? If not, you can ignore the rest of this checklist.
  • 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

/hold
This is breaking change in the configuration API, we need to synchronize

Copy link

codecov bot commented Feb 1, 2024

Codecov Report

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

Project coverage is 67.22%. Comparing base (ab65bc4) to head (d688fe3).
Report is 3 commits behind head on main.

Files Patch % Lines
pkg/pipeline/transform/transform_network.go 45.71% 15 Missing and 4 partials ⚠️
pkg/pipeline/transform/kubernetes/enrich.go 77.27% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #580      +/-   ##
==========================================
+ Coverage   66.97%   67.22%   +0.24%     
==========================================
  Files         104      104              
  Lines        7446     7459      +13     
==========================================
+ Hits         4987     5014      +27     
+ Misses       2162     2143      -19     
- Partials      297      302       +5     
Flag Coverage Δ
unittests 67.22% <65.21%> (+0.24%) ⬆️

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.

@OlivierCazade OlivierCazade force-pushed the transformrulechange branch 4 times, most recently from 164e724 to a34a925 Compare February 2, 2024 15:36
Copy link
Member

@jotak jotak left a comment

Choose a reason for hiding this comment

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

Not yet reviewed in deep, but the approach looks good to me
specializing each rule params via their own struct rather than forcing a generic approach looks much better!
I'll have some work that depends on this, for NETOBSERV-1426

@OlivierCazade OlivierCazade changed the title Refactoring of transform network API NETOBSERV-1500 : Refactoring of transform network API Feb 9, 2024
@OlivierCazade OlivierCazade added the breaking-change This pull request has breaking changes. They should be described in PR description. label Feb 13, 2024
Comment on lines +67 to +72
KubernetesInfra *K8sInfraRule `yaml:"kubernetes_infra,omitempty" json:"kubernetes_infra,omitempty" doc:"Kubernetes infra rule configuration"`
Kubernetes *K8sRule `yaml:"kubernetes,omitempty" json:"kubernetes,omitempty" doc:"Kubernetes rule configuration"`
AddSubnet *NetworkAddSubnetRule `yaml:"add_subnet,omitempty" json:"add_subnet,omitempty" doc:"Add subnet rule configuration"`
AddLocation *NetworkGenericRule `yaml:"add_location,omitempty" json:"add_location,omitempty" doc:"Add location rule configuration"`
AddIPCategory *NetworkGenericRule `yaml:"add_ip_category,omitempty" json:"add_ip_category,omitempty" doc:"Add ip category rule configuration"`
AddService *NetworkAddServiceRule `yaml:"add_service,omitempty" json:"add_service,omitempty" doc:"Add service rule configuration"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems we often have same type of rules applied in a row; on both source & destination for example.

Would it make sense to allow arrays on the objects above ?

Then you will be able to call something like:

api.NetworkTransformRules{{
    Type: api.AddKubernetesRuleType,
    Kubernetes: []api.K8sRule{
      api.K8sRule{
          Input:  "SrcAddr",
          Output: "SrcK8S",
      }, 
      api.K8sRule{
          Input:  "DstAddr",
          Output: "DstK8S",
      },
    },
}}})

We could even get rid of the type by just providing objects 🤔

Copy link
Contributor Author

@OlivierCazade OlivierCazade Feb 19, 2024

Choose a reason for hiding this comment

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

We could remove the type field but this would change consistency with the rest of the API that is using it.

About allowing an array, this mean we would have two nested level of rules instead of having one flat array of rules. This add complexity and I am not sure to see a value in doing it.

Copy link
Member

@jotak jotak left a comment

Choose a reason for hiding this comment

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

lgtm
I don't have a preference regarding Julien's suggestion (having an inner slice in k8s rules) .. it avoids some repetition but makes having an additional nested slice, hard to say which is simpler.
before merging we need to have the operator PR ready for the breaking change

@jotak
Copy link
Member

jotak commented Feb 19, 2024

/lgtm

@jotak
Copy link
Member

jotak commented Feb 19, 2024

@OlivierCazade can you edit the description to briefly explain what are the breaking changes, and give an example of how to convert an old config to a new one? This would help users who are hit by the breaking change to quickly figure out how to handle it

@jotak jotak added no-qe This PR doesn't necessitate QE approval no-doc This PR doesn't require documentation change on the NetObserv operator labels Mar 4, 2024
@jotak
Copy link
Member

jotak commented Mar 4, 2024

I'm adding no-qe / no-doc as there's no user facing changes - I tested myself along with netobserv/network-observability-operator#562

@openshift-ci openshift-ci bot removed the lgtm label Mar 4, 2024
@memodi
Copy link

memodi commented Mar 4, 2024

/ok-to-test

@openshift-ci openshift-ci bot added the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Mar 4, 2024
Copy link

github-actions bot commented Mar 4, 2024

New image:
quay.io/netobserv/flowlogs-pipeline:380f2f0

It will expire after two weeks.

To deploy this build, run from the operator repo, assuming the operator is running:

USER=netobserv VERSION=380f2f0 make set-flp-image

@jotak
Copy link
Member

jotak commented Mar 5, 2024

/lgtm

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

/approve

Copy link

openshift-ci bot commented Mar 5, 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-ci openshift-ci bot added the approved label Mar 5, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 24bf8ce into netobserv:main Mar 5, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved breaking-change This pull request has breaking changes. They should be described in PR description. lgtm no-doc This PR doesn't require documentation change on the NetObserv operator no-qe This PR doesn't necessitate QE approval ok-to-test To set manually when a PR is safe to test. Triggers image build on PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants