package com.hp.autonomy.frontend.find.core.metrics;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.metrics.GaugeService;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;

import static com.hp.autonomy.frontend.find.core.metrics.MetricsConfiguration.FIND_METRICS_TYPE_PROPERTY;
import static com.hp.autonomy.frontend.find.core.metrics.MetricsConfiguration.METRIC_NAME_SEPARATOR;
import static com.hp.autonomy.frontend.find.core.metrics.MetricsController.PUBLIC_METRICS_PATH;

@Controller
@RequestMapping(PUBLIC_METRICS_PATH)
class MetricsController {
    static final String PUBLIC_METRICS_PATH = "/api/public/metrics";
    static final String ADD_METRIC_PATH = "/add";
    static final String METRIC_NAME_PARAM = "metricName";
    static final String METRIC_VALUE_PARAM = "timeInMillis";
    static final String WEB_METRIC_PREFIX = METRIC_NAME_SEPARATOR + "web" + METRIC_NAME_SEPARATOR;

    private final GaugeService gaugeService;
    private final String metricType;

    @Autowired
    public MetricsController(final GaugeService gaugeService,
                             @Value(FIND_METRICS_TYPE_PROPERTY) final String metricType) {
        this.gaugeService = gaugeService;
        this.metricType = metricType;
    }

    @RequestMapping(value = ADD_METRIC_PATH, method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void addMetric(@RequestParam(METRIC_NAME_PARAM) final String metricName,
                          @RequestParam(METRIC_VALUE_PARAM) final double metricValue) {
        gaugeService.submit(metricType + WEB_METRIC_PREFIX + metricName, metricValue);
    }
}

@@ -230,16 +230,95 @@
 ervice;%0A
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;%0A
 import o
@@ -353,16 +353,16 @@
 Status;%0A
-
 import o
@@ -649,24 +649,137 @@
 nseStatus;%0A%0A
+import static com.hp.autonomy.frontend.find.core.metrics.MetricsConfiguration.FIND_METRICS_ENABLED_PROPERTY_KEY;%0A
 import stati
@@ -1082,16 +1082,16 @@
 troller%0A
-
 @Request
@@ -1119,16 +1119,74 @@
 S_PATH)%0A
+@ConditionalOnProperty(FIND_METRICS_ENABLED_PROPERTY_KEY)%0A
 class Me

Disable metrics controller when metrics not enabled (FIND-790)