aboutsummaryrefslogtreecommitdiffstats
path: root/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/HealthMetric.java
blob: 0baee8cc84d04f8c454df663cdcf77e2ddea8c12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.metricsproxy.metric;

import ai.vespa.metricsproxy.metric.model.StatusCode;

import static ai.vespa.metricsproxy.metric.model.StatusCode.DOWN;
import static ai.vespa.metricsproxy.metric.model.StatusCode.UNKNOWN;
import static ai.vespa.metricsproxy.metric.model.StatusCode.UP;

/**
 * TODO: Use MetricsPacket instead of this class.
 *
 * @author Jo Kristian Bergum
 */
public class HealthMetric {
    private final String message;
    private final StatusCode status;
    private final boolean isAlive;

    private HealthMetric(StatusCode status, String message, boolean isAlive) {
        this.message = message;
        this.status = status;
        this.isAlive = isAlive;
    }

    public static HealthMetric get(String status, String message) {
        if (message == null) message = "";
        var statusCode = StatusCode.fromString(status);
        return new HealthMetric(statusCode, message, statusCode == UP);
    }

    public static HealthMetric getDown(String message) {
        return new HealthMetric(DOWN, message, false);
    }

    public static HealthMetric getUnknown(String message) {
        return new HealthMetric(UNKNOWN, message, false);
    }

    public static HealthMetric getOk(String message) {
        return new HealthMetric(UP, message, true);
    }

    public String getMessage() {
        return this.message;
    }

    public StatusCode getStatus() {
        return this.status;
    }

    public boolean isOk() {
        return this.isAlive;
    }
}