-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Kubernetes Integration] Fix for apiserver token expiration #42016
Conversation
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
|
Pinging @elastic/obs-ds-hosted-services (Team:obs-ds-hosted-services) |
This pull request is now in conflicts. Could you fix it? 🙏
|
error_string := fmt.Sprintf("%s", err) | ||
errorUnauthorisedMsg := fmt.Sprintf("unexpected status code %d", http.StatusUnauthorized) | ||
if err != nil && strings.Contains(error_string, errorUnauthorisedMsg) { | ||
count := 2 // We retry twice to refresh the Authorisation token in case of http.StatusUnauthorize = 401 Error | ||
for count > 0 { | ||
if _, errAuth := m.http.RefreshAuthorizationHeader(); errAuth == nil { | ||
events, err = m.prometheusClient.GetProcessedMetrics(m.prometheusMappings) | ||
} | ||
if err != nil { | ||
time.Sleep(m.mod.Config().Period) | ||
count-- | ||
} else { | ||
break | ||
} | ||
} | ||
} |
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.
This code is the same across 3 metricsets, right? Can we place it anywhere and call it from there for the 3 metricsets?
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.
Indeed I tried it but we get in circular dependencies between the packages and the imported interfaces. I guess that this is the reason that it was the same already
@constanca-m , @MichaelKatsoulis I would say we are ready to merge. Let me know if you have any other suggestions |
* initial fix for apiserver * adding fix for controller and schedule (cherry picked from commit 7e25c4d)
* initial fix for apiserver * adding fix for controller and schedule (cherry picked from commit 7e25c4d)
* initial fix for apiserver * adding fix for controller and schedule (cherry picked from commit 7e25c4d)
…ken expiration (#42230) * [Kubernetes Integration] Fix for apiserver token expiration (#42016) * initial fix for apiserver * adding fix for controller and schedule (cherry picked from commit 7e25c4d) * correcting changelog.next.asciidoc file --------- Co-authored-by: Andrew Gizas <andreas.gkizas@elastic.co> Co-authored-by: Denis <denis.rechkunov@elastic.co>
Proposed commit message
WHAT: Adds the ability to NewPrometheusClient to refresh the authentication bearer token
WHY: It is needed in specific K8s metrcisets that use prometheus to retrieve the metrics. In such cases, when the token expires, the client still uses old connection and eventually it gets rejected with 401 unauthorised error
Checklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.How to test this PR locally
Using following documentation to build metricbeat locally
Use only following manifest:
Related issues
Use cases
Reported here: https://github.com/elastic/sdh-beats/issues/5439
Screenshots
For the last 30m or so processing continues
Logs
Consequative messages
message":"OLEEEE--- -> Denotes that prometheus metrics
"message":"PASSSS--- -> Denotes that prometheus metrics got 401 and then refresh of token happens
message":"OLEEEE--- -> Denotes that prometheus metrics continues processing