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-1182 added cluster name to flp configuration #386

Merged
merged 1 commit into from
Aug 4, 2023

Conversation

KalmanMeth
Copy link
Contributor

@KalmanMeth KalmanMeth commented Jun 29, 2023

Added transform_filter to flp pipeline to add a clusterName field to flow logs.
clusterName is taken from config file. If blank, take clusterID from clusterVersion struct.

@codecov
Copy link

codecov bot commented Jun 29, 2023

Codecov Report

Merging #386 (6b70f0e) into main (0d6ebe8) will increase coverage by 2.34%.
Report is 3 commits behind head on main.
The diff coverage is 85.40%.

@@            Coverage Diff             @@
##             main     #386      +/-   ##
==========================================
+ Coverage   53.67%   56.02%   +2.34%     
==========================================
  Files          44       45       +1     
  Lines        5559     5865     +306     
==========================================
+ Hits         2984     3286     +302     
- Misses       2359     2362       +3     
- Partials      216      217       +1     
Flag Coverage Δ
unittests 56.02% <85.40%> (+2.34%) ⬆️

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

Files Changed Coverage Δ
api/v1alpha1/zz_generated.conversion.go 0.25% <0.00%> (-0.01%) ⬇️
api/v1beta1/flowcollector_types.go 100.00% <ø> (ø)
controllers/flowlogspipeline/flp_reconciler.go 67.85% <ø> (-5.32%) ⬇️
controllers/flowcollector_controller.go 55.55% <20.00%> (+0.42%) ⬆️
...ntrollers/flowlogspipeline/flp_monolith_objects.go 88.46% <75.00%> (ø)
...ontrollers/flowlogspipeline/flp_transfo_objects.go 93.68% <75.00%> (ø)
controllers/flowcollector_objects.go 46.91% <77.77%> (+9.62%) ⬆️
controllers/flowlogspipeline/flp_common_objects.go 82.01% <88.18%> (+0.24%) ⬆️
pkg/helper/dashboard.go 96.49% <96.49%> (ø)
api/v1beta1/zz_generated.deepcopy.go 55.36% <100.00%> (+1.58%) ⬆️
... and 5 more

... and 5 files with indirect coverage changes

@KalmanMeth
Copy link
Contributor Author

KalmanMeth commented Jul 2, 2023

@jpinsonneau jpinsonneau changed the title added cluster name to flp configuration NETOBSERV-1182 added cluster name to flp configuration Jul 10, 2023
Comment on lines 439 to 455
//+kubebuilder:default:="defaultCluster"
// +optional
// `clusterName` is the name of the cluster.
ClusterName string `json:"clusterName,omitempty"`

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//+kubebuilder:default:="defaultCluster"
// +optional
// `clusterName` is the name of the cluster.
ClusterName string `json:"clusterName,omitempty"`
//+kubebuilder:default:=""
// +optional
// `clusterName` is the name of the cluster.
ClusterName string `json:"clusterName,omitempty"`

I would suggest to set default as empty to avoid FLP extra stage for single cluster usage. WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we automatically retrieve clusterID from openshift when clusterName is blank, we really cannot distinguish between single cluster vs multi-cluster. To distinguish between them, we would have to add an explicit parameter to the flowcollector config file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Default set to empty.

@@ -45,6 +45,7 @@ const (
conntrackTerminatingTimeout = 5 * time.Second
conntrackEndTimeout = 10 * time.Second
conntrackHeartbeatInterval = 30 * time.Second
clusterNameDefault = "defaultCluster"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
clusterNameDefault = "defaultCluster"

following previous comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed default to blank, but in that case we take the clusterName from Openshift.

@@ -310,15 +311,29 @@ func (b *builder) addTransformStages(stage *config.PipelineBuilderStage) (*corev
lastStage := *stage
indexFields := constants.LokiIndexFields

clusterName := clusterNameDefault
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
clusterName := clusterNameDefault
clusterName := ""

following previous comment

@@ -351,7 +351,7 @@ metadata:
capabilities: Seamless Upgrades
categories: Monitoring
console.openshift.io/plugins: '["netobserv-plugin"]'
containerImage: quay.io/netobserv/network-observability-operator:1.0.3
containerImage: quay.io/meth/network-observability-operator:main
Copy link
Contributor

Choose a reason for hiding this comment

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

you can run make update-bundle to avoid this 😸

.PHONY: update-bundle
update-bundle: IMG=$(IMAGE_TAG_BASE):$(OPERATOR_VERSION)
update-bundle: bundle ## Prepare a clean bundle to be commited

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

//take clustername from openshift
clusterName = string(constants.DefaultClusterID)
}
transformFilterRules := []api.TransformFilterRule{
Copy link
Member

Choose a reason for hiding this comment

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

ClusterName can be empty (e.g. if not setup in CR and not running on openshift) => in that case, I think we should not create this rule

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -436,6 +436,11 @@ type FlowCollectorFLP struct {
// `conversationTerminatingTimeout` is the time to wait from detected FIN flag to end a conversation. Only relevant for TCP flows.
ConversationTerminatingTimeout *metav1.Duration `json:"conversationTerminatingTimeout,omitempty"`

//+kubebuilder:default:=""
// +optional
// `clusterName` is the name of the cluster.
Copy link
Member

Choose a reason for hiding this comment

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

Since this is a user-facing doc, it deserves some explanation, example:

Suggested change
// `clusterName` is the name of the cluster.
// `clusterName` is the name of the cluster to appear in the flows data. This is useful in a multi-cluster context. When using OpenShift, leave empty to make it automatically determined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

Comment on lines 108 to 116
cversion := &configv1.ClusterVersion{}
key := client.ObjectKey{Name: "version"}
if err := r.Client.Get(ctx, key, cversion); err != nil {
log.Error(err, "unable to obtain cluster ID")
} else {
constants.DefaultClusterID = cversion.Spec.ClusterID
}
Copy link
Member

Choose a reason for hiding this comment

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

This block should be run only once, and only for openshift. To do so you can wrap it in a block if r.permissions.Vendor(ctx) == discover.VendorOpenShift && constants.DefaultClusterID == "" {

Copy link
Member

Choose a reason for hiding this comment

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

Also it is unexpected to update a "constant". I would move DefaultClusterID somewhere else. For instance, it could be part of the FlowCollectorReconciler struct, and passed down to reconcilers via newCommonInfo; or if you prefer to keep a global access, maybe create a new file globals.go in package reconcilers ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In order to pass down the clusterName through the series of function calls it would have required many changes and would have made the code ugly. I therefore made it into a global, as suggested.

Copy link
Member

Choose a reason for hiding this comment

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

That's ok
The "CommonInfo" is already done in that purpose, to be passed to the reconcilers, so you wouldn't have to change all the function signatures, just adding it to a struct that is already spread across reconcilers.
But that's ok with the global approach - as long as not everything ends up like that, which would denote a lack of modularity and makes sometimes testing more difficult

}
transformFilterRules := []api.TransformFilterRule{
{
Input: "clusterName",
Copy link
Member

Choose a reason for hiding this comment

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

We should use the same pattern as the other fields, ie:

Suggested change
Input: "clusterName",
Input: "K8S_ClusterName",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@jotak jotak added the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Jul 20, 2023
@github-actions
Copy link

New images:

  • quay.io/netobserv/network-observability-operator:30c2fdc
  • quay.io/netobserv/network-observability-operator-bundle:v0.0.0-30c2fdc
  • quay.io/netobserv/network-observability-operator-catalog:v0.0.0-30c2fdc

They will expire after two weeks.

To deploy this build:

# Direct deployment, from operator repo
IMAGE=quay.io/netobserv/network-observability-operator:30c2fdc make deploy

# Or using operator-sdk
operator-sdk run bundle quay.io/netobserv/network-observability-operator-bundle:v0.0.0-30c2fdc

Or as a Catalog Source:

apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
  name: netobserv-dev
  namespace: openshift-marketplace
spec:
  sourceType: grpc
  image: quay.io/netobserv/network-observability-operator-catalog:v0.0.0-30c2fdc
  displayName: NetObserv development catalog
  publisher: Me
  updateStrategy:
    registryPoll:
      interval: 1m

@jotak
Copy link
Member

jotak commented Jul 20, 2023

/lgtm
thanks @KalmanMeth !
There's one pending question, that we can answer later: should we define K8S_ClusterName as a Loki index? I think we should, since it will become a common aggregating key for queries in a multi-cluster scenario. We can do that later.

PS : looks like the linter is unhappy due to high cyclomatic ...

@openshift-ci openshift-ci bot added lgtm and removed lgtm labels Jul 20, 2023
@github-actions github-actions bot removed the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Jul 24, 2023
@KalmanMeth
Copy link
Contributor Author

PS : looks like the linter is unhappy due to high cyclomatic ...

I refactored a bit to make the linter happy.

@KalmanMeth KalmanMeth requested a review from jotak July 24, 2023 10:44
@jotak
Copy link
Member

jotak commented Jul 24, 2023

Thanks !
/lgtm

@mffiedler
Copy link

mffiedler commented Jul 25, 2023

@KalmanMeth @jotak Can we re-add ok-to-test?
nm - i see tests in progress

@KalmanMeth KalmanMeth added the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Jul 26, 2023
@github-actions
Copy link

New images:

  • quay.io/netobserv/network-observability-operator:d93080e
  • quay.io/netobserv/network-observability-operator-bundle:v0.0.0-d93080e
  • quay.io/netobserv/network-observability-operator-catalog:v0.0.0-d93080e

They will expire after two weeks.

To deploy this build:

# Direct deployment, from operator repo
IMAGE=quay.io/netobserv/network-observability-operator:d93080e make deploy

# Or using operator-sdk
operator-sdk run bundle quay.io/netobserv/network-observability-operator-bundle:v0.0.0-d93080e

Or as a Catalog Source:

apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
  name: netobserv-dev
  namespace: openshift-marketplace
spec:
  sourceType: grpc
  image: quay.io/netobserv/network-observability-operator-catalog:v0.0.0-d93080e
  displayName: NetObserv development catalog
  publisher: Me
  updateStrategy:
    registryPoll:
      interval: 1m

@openshift-ci openshift-ci bot removed the lgtm label Aug 3, 2023
@github-actions github-actions bot removed the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Aug 3, 2023
@KalmanMeth
Copy link
Contributor Author

performed rebase

@KalmanMeth KalmanMeth added the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Aug 3, 2023
@github-actions
Copy link

github-actions bot commented Aug 3, 2023

New images:

  • quay.io/netobserv/network-observability-operator:1a0da20
  • quay.io/netobserv/network-observability-operator-bundle:v0.0.0-1a0da20
  • quay.io/netobserv/network-observability-operator-catalog:v0.0.0-1a0da20

They will expire after two weeks.

To deploy this build:

# Direct deployment, from operator repo
IMAGE=quay.io/netobserv/network-observability-operator:1a0da20 make deploy

# Or using operator-sdk
operator-sdk run bundle quay.io/netobserv/network-observability-operator-bundle:v0.0.0-1a0da20

Or as a Catalog Source:

apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
  name: netobserv-dev
  namespace: openshift-marketplace
spec:
  sourceType: grpc
  image: quay.io/netobserv/network-observability-operator-catalog:v0.0.0-1a0da20
  displayName: NetObserv development catalog
  publisher: Me
  updateStrategy:
    registryPoll:
      interval: 1m

@jotak
Copy link
Member

jotak commented Aug 3, 2023

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Aug 3, 2023
@mffiedler
Copy link

/label qe-approved

Basic testing looks good, can continue QE post-merge

@openshift-ci openshift-ci bot added the qe-approved QE has approved this pull request label Aug 3, 2023
@jpinsonneau
Copy link
Contributor

/approve

@openshift-ci
Copy link

openshift-ci bot commented Aug 4, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jpinsonneau

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 Aug 4, 2023
@openshift-merge-robot openshift-merge-robot merged commit 9d208dd into netobserv:main Aug 4, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. qe-approved QE has approved this pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants