package eu.dnetlib.metrics;

import java.util.Collections;
import java.util.List;

import io.micrometer.core.instrument.DistributionSummary;
import io.micrometer.core.instrument.MeterRegistry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
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.ResponseBody;

/**
 * Created by Alessia Bardi on 2019-06-21.
 *
 * @author Alessia Bardi
 */

@Controller
public final class TestController {

	private static final Log log = LogFactory.getLog(TestController.class);

	private final DistributionSummary counter;

	@Autowired
	public TestController(final MeterRegistry registry) {
		this.counter = DistributionSummary.builder("get.counter.requests")
				.tags("version", "v1")
				.publishPercentileHistogram()
				.register(registry);
	}

	@RequestMapping(value = "/test", method = RequestMethod.GET)
	@ResponseBody
	public List<String> getStudents() {
		log.info("/test [GET]");
		counter.record(10.0); // <-- We shall record latency here
		return Collections.emptyList();
	}



}