Search in sources :

Example 6 with Instance

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

the class SingleTargetMetricsEndpointTest method testfilterInstanceListNegative.

@Test(expected = HttpClientErrorException.class)
public void testfilterInstanceListNegative() {
    // NB: required to set up the test properly
    this.getMetrics("59ff5929-b593-4d90-a3b3-95f4883a8553", "1");
    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);
}
Also used : Target(org.cloudfoundry.promregator.config.Target) Instance(org.cloudfoundry.promregator.scanner.Instance) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 7 with Instance

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

the class TestableMetricsEndpoint method createMetricsFetchers.

@Override
protected List<MetricsFetcher> createMetricsFetchers(List<Instance> instanceList) {
    List<MetricsFetcher> list = new LinkedList<>();
    for (Instance instance : instanceList) {
        MockedMetricsFetcher mf = new MockedMetricsFetcher(instance);
        list.add(mf);
    }
    return list;
}
Also used : Instance(org.cloudfoundry.promregator.scanner.Instance) MetricsFetcher(org.cloudfoundry.promregator.fetcher.MetricsFetcher) LinkedList(java.util.LinkedList)

Example 8 with Instance

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

the class DiscoveryEndpoint method getDiscovery.

@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public DiscoveryResponse[] getDiscovery(HttpServletRequest request) {
    List<Instance> instances = this.appInstanceScanner.determineInstancesFromTargets(this.promregatorConfiguration.getTargets());
    String localHostname = this.myHostname != null ? this.myHostname : request.getLocalName();
    int localPort = this.myPort != 0 ? this.myPort : request.getLocalPort();
    final String[] targets = { String.format("%s:%d", localHostname, localPort) };
    log.info(String.format("Using scraping target %s in discovery response", targets[0]));
    List<DiscoveryResponse> result = new LinkedList<>();
    for (Instance instance : instances) {
        String path = String.format(SingleTargetMetricsEndpoint.ENDPOINT_PATH + "/%s/%s", instance.getApplicationId(), instance.getInstanceNumber());
        DiscoveryLabel dl = new DiscoveryLabel(path, instance);
        DiscoveryResponse dr = new DiscoveryResponse(targets, dl);
        result.add(dr);
    }
    // finally, also add our own metrics endpoint
    DiscoveryLabel dl = new DiscoveryLabel(PromregatorMetricsEndpoint.ENDPOINT_PATH);
    result.add(new DiscoveryResponse(targets, dl));
    log.info(String.format("Returing discovery document with %d targets", result.size()));
    return result.toArray(new DiscoveryResponse[0]);
}
Also used : Instance(org.cloudfoundry.promregator.scanner.Instance) LinkedList(java.util.LinkedList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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