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

fix metrics for image file cache #654

Merged
merged 1 commit into from
Jan 28, 2025
Merged
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
Expand Up @@ -67,6 +67,19 @@
public ImageResultCreator(int maxRollCombinationToCache) {
createCacheIndexFileIfMissing();
MAX_ROLL_COMBINATION_TO_CACHE = BigInteger.valueOf(maxRollCombinationToCache);
Arrays.stream(DiceImageStyle.values())
.flatMap(s -> s.getSupportedColors().stream()
.map(c -> DiceImageStyle.combineStyleAndColorName(s, c)))
.forEach(ri -> {
createFolderIfMissing(ri);
Gauge.builder("diceImage.cache", () -> {
try (Stream<Path> files = Files.list(Paths.get("%s/%s/".formatted(CACHE_FOLDER, ri)))) {
return files.count();
} catch (IOException e) {
return -1;

Check warning on line 79 in bot/src/main/java/de/janno/discord/bot/dice/image/ImageResultCreator.java

View check run for this annotation

Codecov / codecov/patch

bot/src/main/java/de/janno/discord/bot/dice/image/ImageResultCreator.java#L76-L79

Added lines #L76 - L79 were not covered by tests
}
}).tag("type", ri).register(globalRegistry);
});
}

private void createFolderIfMissing(String folderName) {
Expand All @@ -85,16 +98,7 @@
Arrays.stream(DiceImageStyle.values())
.flatMap(s -> s.getSupportedColors().stream()
.map(c -> DiceImageStyle.combineStyleAndColorName(s, c)))
.forEach(ri -> {
createFolderIfMissing(ri);
Gauge.builder("diceImage.cache", () -> {
try (Stream<Path> files = Files.list(Paths.get("%s/%s/".formatted(CACHE_FOLDER, ri)))) {
return files.count();
} catch (IOException e) {
return -1;
}
}).tag("type", ri).register(globalRegistry);
});
.forEach(this::createFolderIfMissing);
}

@VisibleForTesting
Expand Down