fix: Throw better error message if version parsing fails #821
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Agent sends a request to Kibana during
push
operations to check its version number. Unfortunately, the API endpoint responsible for returning this data will always return a2XX
error code, even if credentials are invalid, for reasons, essentially because this endpoint acts as a heartbeat for Kibana in certain cases.Better solution
We can get around this issue by calling
/api/stats
instead of/api/status
. This endpoint returns the Kibana version and will throw a401
in the event of a garbage API key, thus solving both problems.Note: the rest of the info in the description is kept for context, but we will employ the solution explained above.
Example
Explanation
Because we don't receive a
401
, the Agent's internal HTTP error handling will not display any error, per its design. Unfortunately, because this issue falls through to the calling code, when we do receive an error, it is very unhelpful from a UX perspective. At this point, the user is trying topush
their monitors. While waiting with their fingers crossed, hoping to see a success message, receiving a log like the example output below is confusing, disheartening, and a bad experience.My proposal is that the Agent should diagnose this novel error and throw a custom message in this case. The copy is by no means final and I am open to suggestions.I'm aware that this is essentially fixing the problem by introducing tech debt. A longer term alternative fix to this approach would be to have Kibana provide a dedicated version API endpoint that could handle HTTP errors in the conventional way, but having spoken to the team, at this point it seems unlikely we will see this change in the short term. As the "fix" here has a really small footprint and is encapsulated to just this function, it seems acceptable to me, but I'm open to alternative solutions as well.