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

feat(origin health check): add metrics for counting total health checks sent #862

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2013-2021 Expedia Inc.
Copyright (C) 2013-2024 Expedia Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,7 +32,8 @@
*/
public class UrlRequestHealthCheck implements OriginHealthCheckFunction {
private final String healthCheckUri;
private final SimpleCache<Origin, Counter> meterCache;
private final SimpleCache<Origin, Counter> failuresMeter;
private final SimpleCache<Origin, Counter> healthChecksMeter;

/**
* Construct an instance.
Expand All @@ -41,7 +42,8 @@ public class UrlRequestHealthCheck implements OriginHealthCheckFunction {
*/
public UrlRequestHealthCheck(String healthCheckUri, CentralisedMetrics metrics) {
this.healthCheckUri = uriWithInitialSlash(healthCheckUri);
this.meterCache = metrics.proxy().client().originHealthCheckFailures();
this.failuresMeter = metrics.proxy().client().originHealthCheckFailures();
this.healthChecksMeter = metrics.proxy().client().originHealthChecks();
}

private static String uriWithInitialSlash(String uri) {
Expand All @@ -54,15 +56,16 @@ public void check(HttpClient client, Origin origin, OriginHealthCheckFunction.Ca

client.send(request)
.handle((response, cause) -> {
healthChecksMeter.get(origin).increment();
if (response != null) {
if (response.status().equals(OK)) {
responseCallback.originStateResponse(HEALTHY);
} else {
meterCache.get(origin).increment();
failuresMeter.get(origin).increment();
responseCallback.originStateResponse(UNHEALTHY);
}
} else if (cause != null) {
meterCache.get(origin).increment();
failuresMeter.get(origin).increment();
responseCallback.originStateResponse(UNHEALTHY);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2013-2021 Expedia Inc.
Copyright (C) 2013-2024 Expedia Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -79,6 +79,7 @@ public void declaresOriginHealthyOnOkResponseCode() {

assertThat(originState, is(HEALTHY));
assertThat(meters(id -> id.getName().equals("proxy.client.originHealthCheckFailures")).size(), is(0));
assertThat(meters(id -> id.getName().equals("proxy.client.originHealthChecks")).size(), is(1));
}

@Test
Expand All @@ -92,6 +93,7 @@ public void declaresOriginUnhealthyOnNon200Ok() {
assertThat(metrics.getRegistry().find("proxy.client.originHealthCheckFailures")
.tags("originId", someOrigin.id().toString(), "appId", someOrigin.applicationId().toString()).counter().count(), is(1.0));
assertThat(meters(id -> id.getName().equals("proxy.client.originHealthCheckFailures")).size(), is(1));
assertThat(meters(id -> id.getName().equals("proxy.client.originHealthChecks")).size(), is(1));
}

@Test
Expand All @@ -106,6 +108,7 @@ public void declaredOriginUnhealthyOnTransportException() {
.tags("originId", someOrigin.id().toString(), "appId", someOrigin.applicationId().toString()).counter().count(), is(1.0));

assertThat(meters(id -> id.getName().equals("proxy.client.originHealthCheckFailures")).size(), is(1));
assertThat(meters(id -> id.getName().equals("proxy.client.originHealthChecks")).size(), is(1));
}

private List<Meter> meters(Predicate<Meter.Id> predicate) {
Expand Down
Loading
Loading