aboutsummaryrefslogtreecommitdiffstats
path: root/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/HealthMetric.java
blob: 41a8c3d414e6901b3041570e043f3f46366033a7 (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
56
/*
* Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
 */

package ai.vespa.metricsproxy.metric;

/**
 * @author Jo Kristian Bergum
 */
public class HealthMetric {
    private final String message;
    private final String status;
    private final boolean isAlive;

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

    public static HealthMetric get(String status, String message) {
        if (status == null) {
            status = "";
        }
        if (message == null) {
            message = "";
        }
        status = status.toLowerCase();

        if (status.equals("up") || status.equals("ok")) {
            return new HealthMetric(status, message, true);
        } else {
            return new HealthMetric(status, message, false);
        }
    }

    public static HealthMetric getFailed(String message) {
        return new HealthMetric("down", message, false);
    }

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

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

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

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