aboutsummaryrefslogtreecommitdiffstats
path: root/vespaclient-container-plugin/src/main/java/com/yahoo/feedhandler/VespaFeedHandlerStatus.java
blob: ac16159a9bbad09131451903212ac9a280d8c7b2 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.feedhandler;

import java.util.concurrent.Executor;

import com.yahoo.cloud.config.ClusterListConfig;
import com.yahoo.cloud.config.SlobroksConfig;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.container.jdisc.ThreadedHttpRequestHandler;
import com.yahoo.document.config.DocumentmanagerConfig;
import com.yahoo.jdisc.Metric;
import com.yahoo.vespa.config.content.LoadTypeConfig;
import com.yahoo.feedapi.FeedContext;
import com.yahoo.metrics.MetricManager;
import com.yahoo.metrics.MetricSet;
import com.yahoo.vespaclient.config.FeederConfig;

/**
 * @deprecated Legacy API. Will be removed in Vespa 7
 */
// TODO: Remove on Vespa 7
@Deprecated // OK
public class VespaFeedHandlerStatus extends ThreadedHttpRequestHandler {

    private MetricManager manager;

    public VespaFeedHandlerStatus(FeederConfig feederConfig, 
                                  LoadTypeConfig loadTypeConfig,
                                  DocumentmanagerConfig documentmanagerConfig, 
                                  SlobroksConfig slobroksConfig,
                                  ClusterListConfig clusterListConfig,
                                  Executor executor,
                                  Metric metric) {
        this(FeedContext.getInstance(feederConfig, loadTypeConfig,
                                     documentmanagerConfig, slobroksConfig, 
                                     clusterListConfig, metric),
             true, true, executor);
    }

    VespaFeedHandlerStatus(FeedContext context, boolean doLog, boolean makeSnapshots, Executor executor) {
        super(executor);
        manager = new MetricManager();
        final MetricSet metricSet = context.getMetrics().getMetricSet();
        metricSet.unregister();
        manager.registerMetric(metricSet);
        if (doLog) {
            manager.addMetricToConsumer("log", "routes.total.putdocument.count");
            manager.addMetricToConsumer("log", "routes.total.removedocument.count");
            manager.addMetricToConsumer("log", "routes.total.updatedocument.count");
            manager.addMetricToConsumer("log", "routes.total.getdocument.count");

            manager.addMetricToConsumer("log", "routes.total.putdocument.errors.total");
            manager.addMetricToConsumer("log", "routes.total.removedocument.errors.total");
            manager.addMetricToConsumer("log", "routes.total.updatedocument.errors.total");
            manager.addMetricToConsumer("log", "routes.total.getdocument.errors.total");

            manager.addMetricToConsumer("log", "routes.total.putdocument.latency");
            manager.addMetricToConsumer("log", "routes.total.removedocument.latency");
            manager.addMetricToConsumer("log", "routes.total.updatedocument.latency");
            manager.addMetricToConsumer("log", "routes.total.getdocument.latency");
        }

        if (doLog || makeSnapshots) {
            new Thread(manager).start();
        }
    }

    @Override
    public HttpResponse handle(HttpRequest request) {
        try {
            return new StatusResponse(manager, asInt(request.getProperty("verbosity"), 0), asInt(request.getProperty("snapshotperiod"), 0));
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    private int asInt(String value, int defaultValue) {
        if (value == null) return defaultValue;
        return Integer.parseInt(value);
    }

    @Override
    public void destroy() {
        manager.stop();
    }

}