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