aboutsummaryrefslogtreecommitdiffstats
path: root/clustercontroller-reindexer/src/main/java/ai/vespa/reindexing/ReindexingMetrics.java
blob: 83be05d970eb55658f3ce241790b8012d6e0cb0b (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.reindexing;

import ai.vespa.metrics.ClusterControllerMetrics;
import com.yahoo.documentapi.ProgressToken;
import com.yahoo.jdisc.Metric;

import java.time.Clock;
import java.util.EnumSet;
import java.util.Map;

import static ai.vespa.reindexing.Reindexing.State.SUCCESSFUL;

/**
 * Metrics for reindexing in a content cluster.
 *
 * @author jonmv
 */
class ReindexingMetrics {

    private final Metric metric;
    private final String cluster;

    ReindexingMetrics(Metric metric, String cluster) {
        this.metric = metric;
        this.cluster = cluster;
    }

    void dump(Reindexing reindexing) {
        reindexing.status().forEach((type, status) -> {
            metric.set(ClusterControllerMetrics.REINDEXING_PROGRESS.baseName(),
                       status.progress().map(ProgressToken::percentFinished).map(percentage -> percentage * 1e-2)
                             .orElse(status.state() == SUCCESSFUL ? 1.0 : 0.0),
                       metric.createContext(Map.of("clusterid", cluster, "documenttype", type.getName())));
        });
    }

}