Ether Framework
Unified API docs for Ether modules
Loading...
Searching...
No Matches
ProbeAggregator.java
Go to the documentation of this file.
1package dev.rafex.ether.observability.core.probe;
2
3/*-
4 * #%L
5 * ether-observability-core
6 * %%
7 * Copyright (C) 2025 - 2026 Raúl Eduardo González Argote
8 * %%
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
26 * #L%
27 */
28
29import java.util.ArrayList;
30import java.util.List;
31
32/**
33 * Utilidad para agregar resultados de múltiples probes de verificación.
34 * Calcula el estado agregado basado en los resultados individuales.
35 */
36public final class ProbeAggregator {
37
38 private ProbeAggregator() {
39 // Clase de utilidad - no instanciable
40 }
41
42 /**
43 * Agrega los resultados de múltiples probes de verificación.
44 *
45 * @param kind el tipo de probe
46 * @param checks las verificaciones a ejecutar
47 * @return el reporte con el estado agregado
48 */
49 public static ProbeReport aggregate(final ProbeKind kind, final List<ProbeCheck> checks) {
50 final var results = new ArrayList<ProbeResult>();
51 for (final var check : checks == null ? List.<ProbeCheck>of() : checks) {
52 results.add(check.execute());
53 }
54 return new ProbeReport(kind, aggregateStatus(results), results);
55 }
56
57 /**
58 * Calcula el estado agregado basado en los resultados individuales.
59 *
60 * @param results lista de resultados de probes
61 * @return el estado agregado (DOWN si hay algún DOWN, DEGRADED si hay algún DEGRADED, UP si todos UP)
62 */
63 private static ProbeStatus aggregateStatus(final List<ProbeResult> results) {
64 boolean degraded = false;
65 for (final var result : results) {
66 if (result.status() == ProbeStatus.DOWN) {
67 return ProbeStatus.DOWN;
68 }
69 if (result.status() == ProbeStatus.DEGRADED) {
70 degraded = true;
71 }
72 }
73 return degraded ? ProbeStatus.DEGRADED : ProbeStatus.UP;
74 }
75}
static ProbeReport aggregate(final ProbeKind kind, final List< ProbeCheck > checks)
Agrega los resultados de múltiples probes de verificación.
Tipos de probes de verificación disponibles.
Estados de salud disponibles para probes.
DOWN
El servicio no está disponible o no responde.
UP
El servicio está operativo y respondiendo correctamente.
Función para ejecutar una verificación de probe.
record ProbeReport(ProbeKind kind, ProbeStatus status, List< ProbeResult > results)
Reporte de resultados de probes de verificación.