Search in sources :

Example 1 with Instance

use of org.cloudfoundry.promregator.scanner.Instance in project promregator by promregator.

the class SingleTargetMetricsEndpointTest method testfilterInstanceListPositive.

@Test
public void testfilterInstanceListPositive() {
    // NB: required to set up the test properly
    this.getMetrics("129856d2-c53b-4971-b100-4ce371b78070", "42");
    List<Instance> instanceList = new LinkedList<>();
    Target t;
    t = new Target();
    t.setOrgName("unittestorg");
    t.setSpaceName("unittestspace");
    t.setApplicationName("unittestapp");
    t.setPath("/metricsPath");
    t.setProtocol("https");
    instanceList.add(new Instance(t, "129856d2-c53b-4971-b100-4ce371b78070:41", "https://someurl"));
    instanceList.add(new Instance(t, "229856d2-c53b-4971-b100-4ce371b78070:42", "https://someurl"));
    Instance i;
    i = new Instance(t, "129856d2-c53b-4971-b100-4ce371b78070:42", "https://someurl");
    instanceList.add(i);
    List<Instance> result = this.filterInstanceList(instanceList);
    Assert.assertEquals(1, result.size());
    Assert.assertEquals(i, result.get(0));
}
Also used : Target(org.cloudfoundry.promregator.config.Target) Instance(org.cloudfoundry.promregator.scanner.Instance) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with Instance

use of org.cloudfoundry.promregator.scanner.Instance in project promregator by promregator.

the class SingleTargetMetricsEndpoint method filterInstanceList.

@Override
protected List<Instance> filterInstanceList(List<Instance> instanceList) {
    String instanceId = String.format("%s:%s", applicationId, instanceNumber);
    Instance selectedInstance = null;
    for (Instance instance : instanceList) {
        if (instance.getInstanceId().equals(instanceId)) {
            selectedInstance = instance;
            break;
        }
    }
    if (selectedInstance == null) {
        throw new HttpClientErrorException(HttpStatus.NOT_FOUND);
    }
    List<Instance> response = new LinkedList<Instance>();
    response.add(selectedInstance);
    return response;
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Instance(org.cloudfoundry.promregator.scanner.Instance) LinkedList(java.util.LinkedList)

Example 3 with Instance

use of org.cloudfoundry.promregator.scanner.Instance in project promregator by promregator.

the class AbstractMetricsEndpoint method handleRequest.

public String handleRequest() {
    Instant start = Instant.now();
    this.up.clear();
    List<Instance> instanceList = this.appInstanceScanner.determineInstancesFromTargets(this.promregatorConfiguration.getTargets());
    instanceList = this.filterInstanceList(instanceList);
    List<MetricsFetcher> callablesPrep = this.createMetricsFetchers(instanceList);
    LinkedList<Future<HashMap<String, MetricFamilySamples>>> futures = this.startMetricsFetchers(callablesPrep);
    MergableMetricFamilySamples mmfs = waitForMetricsFetchers(futures);
    Instant stop = Instant.now();
    Duration duration = Duration.between(start, stop);
    this.scrape_duration.set(duration.toMillis() / 1000.0);
    if (this.isIncludeGlobalMetrics()) {
        // also add our own (global) metrics
        mmfs.merge(this.gmfspr.determineEnumerationOfMetricFamilySamples(this.collectorRegistry));
    }
    // add also our own request-specific metrics
    mmfs.merge(this.gmfspr.determineEnumerationOfMetricFamilySamples(this.requestRegistry));
    return mmfs.toType004String();
}
Also used : MergableMetricFamilySamples(org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples) Instance(org.cloudfoundry.promregator.scanner.Instance) Instant(java.time.Instant) Future(java.util.concurrent.Future) Duration(java.time.Duration) MergableMetricFamilySamples(org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) MetricsFetcher(org.cloudfoundry.promregator.fetcher.MetricsFetcher) CFMetricsFetcher(org.cloudfoundry.promregator.fetcher.CFMetricsFetcher)

Example 4 with Instance

use of org.cloudfoundry.promregator.scanner.Instance in project promregator by promregator.

the class AbstractMetricsEndpoint method createMetricsFetchers.

protected List<MetricsFetcher> createMetricsFetchers(List<Instance> instanceList) {
    List<MetricsFetcher> callablesList = new LinkedList<>();
    for (Instance instance : instanceList) {
        log.info(String.format("Instance %s", instance.getInstanceId()));
        Target target = instance.getTarget();
        String orgName = target.getOrgName();
        String spaceName = target.getSpaceName();
        String appName = target.getApplicationName();
        String accessURL = instance.getAccessUrl();
        if (accessURL == null) {
            log.warn(String.format("Unable to retrieve hostname for %s/%s/%s; skipping", orgName, spaceName, appName));
            continue;
        }
        AbstractMetricFamilySamplesEnricher mfse = new CFMetricFamilySamplesEnricher(orgName, spaceName, appName, instance.getInstanceId());
        MetricsFetcherMetrics mfm = new MetricsFetcherMetrics(mfse, up);
        MetricsFetcher mf = null;
        if (this.proxyHost != null && this.proxyPort != 0) {
            mf = new CFMetricsFetcher(accessURL, instance.getInstanceId(), this.ae, mfse, this.proxyHost, this.proxyPort, mfm);
        } else {
            mf = new CFMetricsFetcher(accessURL, instance.getInstanceId(), this.ae, mfse, mfm);
        }
        callablesList.add(mf);
    }
    return callablesList;
}
Also used : MetricsFetcherMetrics(org.cloudfoundry.promregator.fetcher.MetricsFetcherMetrics) CFMetricFamilySamplesEnricher(org.cloudfoundry.promregator.rewrite.CFMetricFamilySamplesEnricher) CFMetricsFetcher(org.cloudfoundry.promregator.fetcher.CFMetricsFetcher) Target(org.cloudfoundry.promregator.config.Target) Instance(org.cloudfoundry.promregator.scanner.Instance) AbstractMetricFamilySamplesEnricher(org.cloudfoundry.promregator.rewrite.AbstractMetricFamilySamplesEnricher) MetricsFetcher(org.cloudfoundry.promregator.fetcher.MetricsFetcher) CFMetricsFetcher(org.cloudfoundry.promregator.fetcher.CFMetricsFetcher) LinkedList(java.util.LinkedList)

Example 5 with Instance

use of org.cloudfoundry.promregator.scanner.Instance in project promregator by promregator.

the class MockedMetricsEndpointSpringApplication method appInstanceScanner.

@Bean
public AppInstanceScanner appInstanceScanner() {
    return new AppInstanceScanner() {

        @Override
        public List<Instance> determineInstancesFromTargets(List<Target> targets) {
            LinkedList<Instance> result = new LinkedList<>();
            Target t = new Target();
            t.setOrgName("unittestorg");
            t.setSpaceName("unittestspace");
            t.setApplicationName("unittestapp");
            t.setPath("/path");
            t.setProtocol("https");
            result.add(new Instance(t, "faedbb0a-2273-4cb4-a659-bd31331f7daf:0", "http://localhost:1234"));
            result.add(new Instance(t, "faedbb0a-2273-4cb4-a659-bd31331f7daf:1", "http://localhost:1234"));
            t = new Target();
            t.setOrgName("unittestorg");
            t.setSpaceName("unittestspace");
            t.setApplicationName("unittestapp2");
            t.setPath("/otherpath");
            t.setProtocol("http");
            result.add(new Instance(t, "1142a717-e27d-4028-89d8-b42a0c973300:0", "http://localhost:1235"));
            return result;
        }
    };
}
Also used : AppInstanceScanner(org.cloudfoundry.promregator.scanner.AppInstanceScanner) Target(org.cloudfoundry.promregator.config.Target) Instance(org.cloudfoundry.promregator.scanner.Instance) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) Bean(org.springframework.context.annotation.Bean)

Aggregations

Instance (org.cloudfoundry.promregator.scanner.Instance)8 LinkedList (java.util.LinkedList)7 Target (org.cloudfoundry.promregator.config.Target)4 MetricsFetcher (org.cloudfoundry.promregator.fetcher.MetricsFetcher)3 CFMetricsFetcher (org.cloudfoundry.promregator.fetcher.CFMetricsFetcher)2 Test (org.junit.Test)2 MetricFamilySamples (io.prometheus.client.Collector.MetricFamilySamples)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 List (java.util.List)1 Future (java.util.concurrent.Future)1 MetricsFetcherMetrics (org.cloudfoundry.promregator.fetcher.MetricsFetcherMetrics)1 AbstractMetricFamilySamplesEnricher (org.cloudfoundry.promregator.rewrite.AbstractMetricFamilySamplesEnricher)1 CFMetricFamilySamplesEnricher (org.cloudfoundry.promregator.rewrite.CFMetricFamilySamplesEnricher)1 MergableMetricFamilySamples (org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples)1 AppInstanceScanner (org.cloudfoundry.promregator.scanner.AppInstanceScanner)1 Bean (org.springframework.context.annotation.Bean)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1