-
Notifications
You must be signed in to change notification settings - Fork 15
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
Ecto decode clusters discovery #649
Ecto decode clusters discovery #649
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately the pipeline is failing here
I ran cypress locally and I get failures, did you try that locally, too?
Not sure if this helps, but I noticed quite some (many duplication) discarded_discovery_events
.
Are those expected to be discarded? 🤔
EDIT: here's how it fails locally, seems the same failure of the pipeline.
Yep, I was just testing and indeed I get the same failures locally (e.g. cluster names are missing from some places, etc). Looking into it now. |
I'd guess that there are some payloads being sent during the E2e tests that include some additional arrays receiving |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @rtorrero ,
I did an initial review.
Couldn't check all the changes in the cluster_policy.ex
file.
In any case, as long as the unit tests and the E2E tests are failling, some changes look required
lib/trento/application/integration/discovery/payloads/cluster/cluster_discovery_payload.ex
Outdated
Show resolved
Hide resolved
lib/trento/application/integration/discovery/payloads/cluster/cib_discovery_payload.ex
Outdated
Show resolved
Hide resolved
lib/trento/application/integration/discovery/payloads/cluster/crmmon_discovery_payload.ex
Outdated
Show resolved
Hide resolved
lib/trento/application/integration/discovery/payloads/cluster/crmmon_discovery_payload.ex
Show resolved
Hide resolved
use Trento.Type | ||
|
||
deftype do | ||
embeds_one :config, SBDConfig do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could maybe define this field as a map. I think that sbd has more options than these ones, and as we don't really do any real validation, a map would work.
This is basically the information coming from the sbd configuration file, which has a key=value
format, and mapping all the flags here looks a bit an overkill
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to agree with Xabi.
What I can say is that if we mapped ALL the fields and we're sure about that, we could also keep it like this.
Otherwise, if we are not fully confident we could be a bit less rigid as xabi is suggesting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I just checked a bit and there is indeed at least one more field that we are not tracking right now. Let's just switch it to a map.
First thing I'd say let's clearly identify the cause, which might be very well what you mention, and if that's the case it makes sense to make sure all lists fields, if received as |
It should be passing now; I wasn't properly handling cases where there is no SID on the payload. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @rtorrero ,
A long journey hehe
I find the PR really good, and I'm approving it, but still adding some comments.
I find having the to_list
usage in the cluster policy code is a pretty big smell. The lists should already be sanitazed in the payload.
Besides that, we should open a tech-debt ticket in our backlog to change the agent to send empty lists properly instead of null
values. I find that at any time this code might explode because we receive some null
where we have the embeds_many
option. And I think we should work on this sooner than later.
I couldn't really review the policy side, I hope that having the tests passing is our best review here, as the code is just an adaptation rather than new changes
Congratulations for the great work!
lib/trento/application/integration/discovery/payloads/cluster/cib_discovery_payload.ex
Outdated
Show resolved
Hide resolved
lib/trento/application/integration/discovery/payloads/cluster/cib_discovery_payload.ex
Show resolved
Hide resolved
lib/trento/application/integration/discovery/payloads/cluster/sbd_discovery_payload.ex
Outdated
Show resolved
Hide resolved
lib/trento/application/integration/discovery/payloads/cluster/crmmon_discovery_payload.ex
Show resolved
Hide resolved
lib/trento/application/integration/discovery/policies/cluster_policy.ex
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[...] I find having the
to_list
usage in the cluster policy code is a pretty big smell. [...][...] tech-debt ticket in our backlog to change the agent to send empty lists properly instead of
null
values. [...]
at any time this code might explode [...]
I embrace @arbulu89 comments, we can improve code smells (not by making them smell more ) and make the involved parties - agent and server - to properly adhere to the contracts.
Great effort nevertheless! Thanks!
Approving, hope tests cover enough 😅
Let's be ready to act if anything comes up
7ab1940
to
29810c3
Compare
This big PR basically continues the effort to use Ecto to define and validate the payloads for the different discovery policies, already started by PRs #602, #595, #582.
This time it's the turn for the cluster discovery. Some notes/clarifications:
Because it feels "wrong" to have all the boilerplate to create a new deftype just for one or few fields. The line on when to do this vs using a deftype is a bit blurry to me, so suggestions accepted on that.
cast(attrs, [])
(cast with nothing to cast) to be able to define deftypes that are pure nested structs (with no fields). Thanks to @fabriziosestito for poiting this out, looked weird initially but it makes sense now:null
on a field that should have a list. This causes the payload validation to fail, and for such cases, the "workaround" that @arbulu89 came up with was to convert these fields to lists before thechangeset
get's called, passing afiltered_attrs
to it.Comments appreciated!