Skip to content

Commit

Permalink
Ignore openmetrics version when determining openmetrics support
Browse files Browse the repository at this point in the history
  • Loading branch information
ToMe25 committed Sep 19, 2023
1 parent 7f4599d commit 4988c8f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
21 changes: 2 additions & 19 deletions src/prometheus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,25 +264,7 @@ size_t prom::writeMetricMetadataLine(char *buffer, const char (&field_name)[fnm_
#if ENABLE_PROMETHEUS_SCRAPE_SUPPORT == 1
bool prom::acceptsOpenMetrics(const char *accept_str) {
const char *start = strstr(accept_str, "application/openmetrics-text");
if (start == NULL) {
return false;
}

while (start != NULL) {
const char *end = strchr(start, ',');
if (end == NULL) {
end = start + strlen(start);
}

const char *result = strstr(start, "version=1.0.0");
if (result != NULL && result < end) {
return true;
}

start = strstr(end, "application/openmetrics-text");
}

return false;
return start != NULL;
}

web::ResponseData prom::handleMetrics(AsyncWebServerRequest *request) {
Expand All @@ -293,6 +275,7 @@ web::ResponseData prom::handleMetrics(AsyncWebServerRequest *request) {
} else {
log_d("Client doesn't accept openmetrics.");
}

const String metrics = getMetrics(openmetrics);
AsyncWebServerResponse *response =
request->beginResponse(200,
Expand Down
2 changes: 1 addition & 1 deletion src/prometheus.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ size_t writeMetricMetadataLine(char *buffer, const char (&field_name)[fnm_l],
* Checks whether the given Accept header accepts openmetrics text protocol version 1.0.0.
*
* @param accept_str The Accept header to check.
* @return True if the given header specifies that the client is openmetrics compliant.
* @return True if the given header contains "application/openmetrics-text".
*/
bool acceptsOpenMetrics(const char *accept_str);

Expand Down

0 comments on commit 4988c8f

Please sign in to comment.