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));
}
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;
}
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);
}
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;
}
};
}
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);
}
Aggregations