Skip to content

Commit

Permalink
Merge pull request #60 from fedinskiy/fix/unupdated
Browse files Browse the repository at this point in the history
Liveness probe for GraphQL client and additional colors for monthly stats
  • Loading branch information
rsvoboda authored Jul 29, 2024
2 parents f8577cc + e863281 commit b52fb82
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.quarkus.activity;

import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Optional;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
Expand Down Expand Up @@ -46,4 +46,8 @@ public OpenPullRequestsQueueByRepositories getOpenPrQueueInOrganization() throws
private OpenPullRequestsQueueByRepositories buildOpenPrQueueInOrganization() throws IOException {
return gitHubService.getOpenPrQueueInOrganization(quarkusQeOrganization);
}

public synchronized Optional<LocalDateTime> getLastUpdated() {
return Optional.ofNullable(openPrQueueInOrganization).map(queue -> queue.updated);
}
}
41 changes: 41 additions & 0 deletions src/main/java/io/quarkus/activity/HangCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.quarkus.activity;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.HealthCheckResponseBuilder;
import org.eclipse.microprofile.health.Liveness;

import java.time.LocalDateTime;

@ApplicationScoped
@Liveness
/*
GraphQL client may stop to retrieve data properly (https://github.com/quarkusio/quarkus/issues/42029),
but restarting the app solves the problem.
This class creates a liveness endpoint and checks, that PR queue was updated at least two hours ago.
If it wasn't (ie last 12 requests failed), the next liveness probe will fail and the pod restarted
*/
public class HangCheck implements HealthCheck {

@Inject
GitHubOpenPrQueueService prService;

@Override
public HealthCheckResponse call() {
HealthCheckResponseBuilder builder = HealthCheckResponse.named("GraphQL updates check");
LocalDateTime twoHoursAgo = LocalDateTime.now().minusHours(2);

builder.up();
prService.getLastUpdated()
.filter(lastUpdated -> lastUpdated.isBefore(twoHoursAgo))
.ifPresent(lastUpdated -> {
builder.down();
builder.withData("lastUpdate", lastUpdated.toString());
});

return builder.build();
}
}
2 changes: 2 additions & 0 deletions src/main/java/io/quarkus/activity/graphql/GraphQLClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.activity.graphql;

import io.vertx.core.json.JsonObject;
import jakarta.inject.Singleton;
import org.eclipse.microprofile.faulttolerance.Retry;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

Expand All @@ -12,6 +13,7 @@

@Retry(delay = 2, delayUnit = SECONDS)
@RegisterRestClient(baseUri = "https://api.github.com/graphql")
@Singleton
public interface GraphQLClient {

@POST
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ quarkus.http.auth.permission.roles.enabled=${activity.security.enabled}
# restrict access to identities with 'quarkus-qe' role
quarkus.http.auth.policy.roles-policy.roles-allowed=quarkus-qe

#Permit Kubernetest/OCP to access health endpoints without authorisation
quarkus.http.auth.permission.probes.paths=/q/health/*
quarkus.http.auth.permission.probes.policy=permit
quarkus.http.auth.permission.probes.methods=GET

quarkus.oidc.enabled=${activity.security.enabled}
quarkus.oidc.application-type=web-app
quarkus.oidc.auth-server-url=${oidc-server-url:}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/templates/monthlyStats.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,16 @@ <h2>Issues created per month in QuarkusIO GitHub organisation</h2>
}
}
function getColor(index) {
// there are currently 8 of us, +1 for a backup
if (index == 0) { return 'rgba(255, 99, 132, 0.8)'}
if (index == 1) { return 'rgba(255, 159, 64, 0.8)'}
if (index == 2) { return 'rgba(255, 205, 86, 0.8)'}
if (index == 3) { return 'rgba(75, 192, 192, 0.8)'}
if (index == 4) { return 'rgba(54, 162, 245, 0.8)'}
if (index == 5) { return 'rgba(153, 102, 255, 0.8)'}
if (index == 6) { return 'rgba(191, 201, 202, 0.8)'}
if (index == 7) { return 'rgba(29, 191, 58, 0.8)'}
if (index == 8) { return 'rgba(1, 1, 1, 0.8)'}
var letters = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++ ) {
Expand Down

0 comments on commit b52fb82

Please sign in to comment.