Search in sources :

Example 1 with Target

use of org.cloudfoundry.promregator.config.Target 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 Target

use of org.cloudfoundry.promregator.config.Target 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 3 with Target

use of org.cloudfoundry.promregator.config.Target in project promregator by promregator.

the class ReactiveAppInstanceScannerTest method testStraightForward.

@Test
public void testStraightForward() {
    List<Target> targets = new LinkedList<>();
    Target t = new Target();
    t.setOrgName("unittestorg");
    t.setSpaceName("unittestspace");
    t.setApplicationName("testapp");
    t.setPath("/testpath1");
    t.setProtocol("http");
    targets.add(t);
    t = new Target();
    t.setOrgName("unittestorg");
    t.setSpaceName("unittestspace");
    t.setApplicationName("testapp2");
    t.setPath("/testpath2");
    t.setProtocol("https");
    targets.add(t);
    List<Instance> result = this.appInstanceScanner.determineInstancesFromTargets(targets);
    boolean testapp1_instance1 = false;
    boolean testapp1_instance2 = false;
    boolean testapp2_instance1 = false;
    for (Instance instance : result) {
        String instanceId = instance.getInstanceId();
        if (instanceId.equals(CFAccessorMock.UNITTEST_APP1_UUID + ":0")) {
            testapp1_instance1 = true;
            Assert.assertEquals("http://hostapp1.shared.domain.example.org/testpath1", instance.getAccessUrl());
        } else if (instanceId.equals(CFAccessorMock.UNITTEST_APP1_UUID + ":1")) {
            testapp1_instance2 = true;
            Assert.assertEquals("http://hostapp1.shared.domain.example.org/testpath1", instance.getAccessUrl());
        } else if (instanceId.equals(CFAccessorMock.UNITTEST_APP2_UUID + ":0")) {
            testapp2_instance1 = true;
            Assert.assertEquals("https://hostapp2.shared.domain.example.org/additionalPath/testpath2", instance.getAccessUrl());
        }
    }
    Assert.assertTrue(testapp1_instance1);
    Assert.assertTrue(testapp1_instance2);
    Assert.assertTrue(testapp2_instance1);
}
Also used : Target(org.cloudfoundry.promregator.config.Target) LinkedList(java.util.LinkedList) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Target

use of org.cloudfoundry.promregator.config.Target 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)

Example 5 with Target

use of org.cloudfoundry.promregator.config.Target 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)

Aggregations

LinkedList (java.util.LinkedList)5 Target (org.cloudfoundry.promregator.config.Target)5 Instance (org.cloudfoundry.promregator.scanner.Instance)4 Test (org.junit.Test)3 List (java.util.List)1 CFMetricsFetcher (org.cloudfoundry.promregator.fetcher.CFMetricsFetcher)1 MetricsFetcher (org.cloudfoundry.promregator.fetcher.MetricsFetcher)1 MetricsFetcherMetrics (org.cloudfoundry.promregator.fetcher.MetricsFetcherMetrics)1 AbstractMetricFamilySamplesEnricher (org.cloudfoundry.promregator.rewrite.AbstractMetricFamilySamplesEnricher)1 CFMetricFamilySamplesEnricher (org.cloudfoundry.promregator.rewrite.CFMetricFamilySamplesEnricher)1 AppInstanceScanner (org.cloudfoundry.promregator.scanner.AppInstanceScanner)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Bean (org.springframework.context.annotation.Bean)1