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-155: Added sampling field to console frontend configuration #264

Merged
merged 3 commits into from
Feb 22, 2023

Conversation

OlivierCazade
Copy link
Contributor

Added sampling field to configuration.

To do that I needed to keep a reference to the FlowCollectorSpec object in the console object builder so I added a bit of refactoring to only keep this object and remove ConsolePlugin and Loki reference which are not needed anymore.

@openshift-ci-robot
Copy link
Collaborator

openshift-ci-robot commented Feb 13, 2023

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

In response to this:

Added sampling field to configuration.

To do that I needed to keep a reference to the FlowCollectorSpec object in the console object builder so I added a bit of refactoring to only keep this object and remove ConsolePlugin and Loki reference which are not needed anymore.

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 kubernetes/test-infra repository.

if b.desiredLoki != nil && b.desiredLoki.TLS.Enable && !b.desiredLoki.TLS.InsecureSkipVerify {
volumes, volumeMounts = helper.AppendCertVolumes(volumes, volumeMounts, &b.desiredLoki.TLS, lokiCerts, b.cWatcher)
args := buildArgs(&b.desired.ConsolePlugin, &b.desired.Loki)
if b.desired != nil && b.desired.Loki.TLS.Enable && !b.desired.Loki.TLS.InsecureSkipVerify {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you still need to check b.desired.Loki != nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

b.desiredLoki was a pointer while b.desired.Loki is not, we only need to check b.desired here

@@ -110,13 +110,14 @@ func TestContainerUpdateCheck(t *testing.T) {
//equals specs
plugin := getPluginConfig()
loki := &flowsv1alpha1.FlowCollectorLoki{URL: "http://loki:3100/", TenantID: "netobserv"}
builder := newBuilder(testNamespace, testImage, &plugin, loki, &certWatcher)
spec := &flowsv1alpha1.FlowCollectorSpec{ConsolePlugin: plugin, Loki: *loki}
builder := newBuilder(testNamespace, testImage, spec, &certWatcher)
Copy link
Contributor

Choose a reason for hiding this comment

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

(Minor) For loki, there's no point in taking the address of (&) only to dereference it back (*) in the next line.  Also, you might then want spec to be consistent.

loki := flowsv1alpha1.FlowCollectorLoki{URL: "http://loki:3100/", TenantID: "netobserv"}
spec := flowsv1alpha1.FlowCollectorSpec{ConsolePlugin: plugin, Loki: loki}
builder := newBuilder(testNamespace, testImage, &spec, &certWatcher)

If you do this, make sure you change it in all the other places in the code.

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, thanks!

return int(*spec.Agent.EBPF.Sampling)
}
return int(spec.Agent.IPFIX.Sampling)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why adding this util in the api types file, can you move to pkg/helpers ? it can be an utility api doesn't need to be a method right ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Until now, helper directly related to the API were added here. Similar to UseEBPF, UseIPFIX...

It does not need to be a method but it improve code readability IMO.

I count 9 helper function, do you think we should move all of them in a new helper package?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think so giving we will have different versions it will be a hassle, do we need to copy them to newer version or keep in the old one what if we need to delete the old api so additional Maintenance for no reason imo

Copy link
Member

Choose a reason for hiding this comment

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

@msherif1234 Personally I've found these methods quite nice to use and I don't think I'm alone - but for sure they have to stay trivial being just syntactic sugar, directly tied to nothing but the model itself, IMO.

I don't really get the comment on the maintenance hassle: if we use helpers, that would be the same, or even worse, as they still need to be duplicated per crd version? When creating a new version, we just copy from the existing one, update the package name and that's it. Am I missing something here?

Copy link
Contributor

@msherif1234 msherif1234 Feb 20, 2023

Choose a reason for hiding this comment

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

I am not against the apis, my comment was about their location , they don't need to be in the api file I just suggested move them to helper pkg taht is it
as u know we have now v1alpha1, v1beta1 and at somepoint v1beta2 so are u gone copy them to all those apis header or keep them in v1alpha1, let me ask this what is the issue moving them out of the xxx_types.go to helper pkg ?

Copy link
Member

Choose a reason for hiding this comment

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

@jpinsonneau , I think Olivier's point is something like that: imagine I have a "UseMTLS" helper defined as:

func (tls *ClientTLS) UseMTLS() bool { return tls.UserCert.Name != "" }

Since ClientTLS is a struct embedded inside FlowCollector and used in different places, with your proposal we would have to duplicate this helper for each embedded case, such as:

func (dc *Desired) KafkaUseMTLS() bool {
	return dc.flowCollector.Spec.Kafka.TLS.UserCert.Name != ""
}

func (dc *Desired) LokiUseMTLS() bool {
	return dc.flowCollector.Spec.Loki.TLS.UserCert.Name != ""
}

Copy link
Contributor

Choose a reason for hiding this comment

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

We already created another helper relying on functions for that situation. I'm not saying we should have only one solution; just adapt according to the needs.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you guys are not confortable with these changes, feel free to rollback and let's take more time to see the impacts.

Copy link
Member

Choose a reason for hiding this comment

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

I think relying sometimes on external helpers and sometimes on a solution based on a Desired wrapper would only make things worse when writing code and looking to retrieve those helpers.

I'll give my +1 to the PR to not block it any further (too much time and energy spent here) but with the feeling that I don't think we've improved the code here

/lgtm

Copy link
Member

Choose a reason for hiding this comment

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

Epilogue: the topic triggered some discussion with the API team, having functions in api was not explicitly prohibited, but they said they will add that to their convention doc. My understanding is that our functions are not fundamentally bad but they need clear guidelines in order to ease their review process so they will prohibit that. So, given we want to follow those conventions (as much as possible), that's a win for the helper approach.

namespace string
labels map[string]string
selector map[string]string
desired *flowsv1alpha1.FlowCollectorSpec
Copy link
Contributor

Choose a reason for hiding this comment

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

pls update your view we need to use flowslatest.FlowCollectorSpec here and everywhere v1alpha1 is referenced

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, thanks!

func (spec *FlowCollectorSpec) UseEBPF() bool { return spec.Agent.Type == AgentEBPF }
func (spec *FlowCollectorSpec) UseIPFIX() bool { return spec.Agent.Type == AgentIPFIX }
func (spec *FlowCollectorSpec) UseKafka() bool { return spec.DeploymentModel == DeploymentModelKafka }

Copy link
Member

Choose a reason for hiding this comment

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

(by the way, I don't think it was necessary to add the new helper to the v1alpha1 version, and maybe not doing so would have spared us from the controversy 😅)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Operator controller now point to v1beta1, this functions were not used anyway

@OlivierCazade
Copy link
Contributor Author

/approve

@openshift-ci
Copy link

openshift-ci bot commented Feb 22, 2023

[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-robot openshift-merge-robot merged commit 7e7a9f8 into netobserv:main Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants