Merge pull request #1576 from yabinmeng/rm-docker-metrics

Fix the Prometheus Push metrics reporter authentication configuration issue
This commit is contained in:
Jonathan Shook 2023-09-29 17:27:13 -05:00 committed by GitHub
commit a50ccc3cac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,6 +31,7 @@ import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandler;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Clock;
import java.time.Duration;
@ -98,15 +99,18 @@ public class PromPushReporter extends ScheduledReporter implements NBConfigurabl
bearerToken = null;
if (optionalApikeyfile.isPresent()) {
keyfilePath = optionalApikeyfile.map(Path::of).orElseThrow();
logger.info("Reading Bearer Token from %s", keyfilePath);
PromPushKeyFileReader keyfile = new PromPushKeyFileReader(keyfilePath);
bearerToken = "Bearer " + keyfile.get();
if (Files.isRegularFile(keyfilePath)) {
logger.info("Reading Bearer Token from %s", keyfilePath);
PromPushKeyFileReader keyfile = new PromPushKeyFileReader(keyfilePath);
bearerToken = keyfile.get();
}
} else if (optionalApikey.isPresent()) {
bearerToken = "Bearer " + optionalApikey.get();
bearerToken = optionalApikey.get();
}
needsAuth = (null != bearerToken);
bearerToken = "Bearer " + bearerToken;
}
@Override
public synchronized void report(
SortedMap<String, Gauge> gauges,