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

Make discovery payload nullable in schema #2638

Merged
merged 1 commit into from
Jun 10, 2024
Merged

Conversation

arbulu89
Copy link
Contributor

@arbulu89 arbulu89 commented May 20, 2024

Description

Make discovery payload nullable in schema.
This field can be null when for example a host doesn't have a cluster installed.

This bug affects the scenario when a cluster node is removed from the cluster, because we wouldn't remove it properly as the discovery fails. This is unlikely scenario. But it happens.
Besides that, we remove an "wrong" error log in the agent side.
This error in the agent:

11:49:26.350 request_id=F9EwDTjMRMb4yvsAB4oR [info] POST /api/v1/collect
11:49:26.350 request_id=F9EwDTjMRMb4yvsAB4oR [debug] Processing with TrentoWeb.V1.DiscoveryController.collect/2
  Parameters: %{"agent_id" => "8b8f6760-e9f5-5014-893d-b154c537e964", "discovery_type" => "ha_cluster_discovery", "payload" => nil}
  Pipelines: [:api, :apikey_authenticated, :api_v1]
11:49:26.358 request_id=F9EwDTjMRMb4yvsAB4oR [debug] QUERY OK source="settings" db=6.1ms queue=0.4ms idle=249.3ms
SELECT s0."id", s0."api_key_settings_jti", s0."api_key_settings_created_at", s0."api_key_settings_expire_at", s0."inserted_at", s0."updated_at", s0."type" FROM "settings" AS s0 WHERE (s0."type" = 'api_key_settings') []
11:49:26.358 request_id=F9EwDTjMRMb4yvsAB4oR [info] Sent 422 in 7ms
11:49:26.358 request_id=F9EwDTjMRMb4yvsAB4oR [debug] TrentoWeb.V1.DiscoveryController halted in OpenApiSpex.Plug.CastAndValidate.call/2

FYI: @abravosuse

How was this tested?

Test added

@arbulu89 arbulu89 added the bug Something isn't working label May 20, 2024
Copy link
Contributor

@abravosuse abravosuse left a comment

Choose a reason for hiding this comment

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

If it is possible to have a PR environment for this, I will test the corresponding image. If not, I approve it now and will test in rolling once merged.

@arbulu89 arbulu89 added the env Create an ephimeral environment for the pr branch label May 20, 2024
@arbulu89
Copy link
Contributor Author

If it is possible to have a PR environment for this, I will test the corresponding image. If not, I approve it now and will test in rolling once merged.

PR env on the way!

@arbulu89 arbulu89 marked this pull request as ready for review May 20, 2024 13:15
@dottorblaster
Copy link
Contributor

It looks good, maybe I'm saying something really weird but shouldn't we also apply some kind of check in the agent to guard against sending nil payloads?

Anyway, if it's just a matter of adding a nullable: true to a schema I'm pretty much in favor of this 👍

@arbulu89 arbulu89 requested review from EMaksy and removed request for dottorblaster May 20, 2024 13:19
Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

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

LGTM

@arbulu89
Copy link
Contributor Author

arbulu89 commented May 20, 2024

@al

It looks good, maybe I'm saying something really weird but shouldn't we also apply some kind of check in the agent to guard against sending nil payloads?

Anyway, if it's just a matter of adding a nullable: true to a schema I'm pretty much in favor of this 👍

But sending null is an existing scenario. For example in this case, that you don't have a cluster. And we work based on this nil.
If we would like to change the behaviour, we would need to change agent and web code, both. And not only the schema

Copy link
Contributor

@dottorblaster dottorblaster left a comment

Choose a reason for hiding this comment

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

You're right @arbulu89, no other questions 👍

Copy link
Contributor

@abravosuse abravosuse left a comment

Choose a reason for hiding this comment

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

I've tested this with the PR environment. Now I don't see errors in the agent journal. What I see is the following:
May 20 13:32:05 vmnwhso01 trento-agent[2238]: time="2024-05-20 13:32:05" level=info msg="ha_cluster_discovery discovery tick output: No HA cluster discovered on this host"

Copy link
Contributor

@rtorrero rtorrero left a comment

Choose a reason for hiding this comment

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

Nice catch @arbulu89 @abravosuse ! LGTM

Copy link
Member

@EMaksy EMaksy left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@gagandeepb gagandeepb left a comment

Choose a reason for hiding this comment

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

Question/comment : If I understood this PR correctly OpenAPI 3.1 has no support for nullable. However, I am not sure to what version of the OpenAPI spec the elixir library implementation (open-api-spex; we are using version 3.11 of this library) maintains conformance. Something that needs further looking into, perhaps ?

@arbulu89
Copy link
Contributor Author

Question/comment : If I understood this PR correctly OpenAPI 3.1 has no support for nullable. However, I am not sure to what version of the OpenAPI spec the elixir library implementation (open-api-spex; we are using version 3.11 of this library) maintains conformance. Something that needs further looking into, perhaps ?

By now it is compliant to 3.0.x version set.
So we should be fine.
If they change, we would need to apply more changes I guess.
But good point. We will need to have an eye on it

@arbulu89 arbulu89 merged commit 24e74e9 into main Jun 10, 2024
76 checks passed
@arbulu89 arbulu89 deleted the accept-payload-nil branch June 10, 2024 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working env Create an ephimeral environment for the pr branch
Development

Successfully merging this pull request may close these issues.

8 participants