Search in sources :

Example 6 with ResolvedTarget

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

the class CFMultiDiscoverer method discover.

/**
 * performs the discovery based on the configured set of targets in the configuration, (pre-)filtering the returned set applying the filter criteria supplied.
 * The instances discovered are automatically registered at this Discoverer
 * @param applicationIdFilter the (pre-)filter based on ApplicationIds, allowing to early filter the list of instances to discover
 * @param instanceFilter the (pre-)filter based on the Instance instance, allowing to filter the lost if instances to discover
 * @return the list of Instances which were discovered (and registered).
 */
@Nullable
public List<Instance> discover(@Nullable Predicate<? super String> applicationIdFilter, @Nullable Predicate<? super Instance> instanceFilter) {
    log.debug(String.format("We have %d targets configured", this.promregatorConfiguration.getTargets().size()));
    List<ResolvedTarget> resolvedTargets = this.targetResolver.resolveTargets(this.promregatorConfiguration.getTargets());
    if (resolvedTargets == null) {
        log.warn("Target resolved was unable to resolve configured targets");
        return Collections.emptyList();
    }
    log.debug(String.format("Raw list contains %d resolved targets", resolvedTargets.size()));
    List<Instance> instanceList = this.appInstanceScanner.determineInstancesFromTargets(resolvedTargets, applicationIdFilter, instanceFilter);
    if (instanceList == null) {
        log.warn("Instance Scanner unable to determine instances from provided targets");
        return Collections.emptyList();
    }
    log.debug(String.format("Raw list contains %d instances", instanceList.size()));
    // ensure that the instances are registered / touched properly
    for (Instance instance : instanceList) {
        this.registerInstance(instance);
    }
    return instanceList;
}
Also used : Instance(org.cloudfoundry.promregator.scanner.Instance) ResolvedTarget(org.cloudfoundry.promregator.scanner.ResolvedTarget) Nullable(javax.annotation.Nullable)

Example 7 with ResolvedTarget

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

the class MockedMetricsEndpointSpringApplication method appInstanceScanner.

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

        @Override
        public List<Instance> determineInstancesFromTargets(List<ResolvedTarget> targets, @Nullable Predicate<? super String> applicationIdFilter, @Nullable Predicate<? super Instance> instanceFilter) {
            LinkedList<Instance> result = new LinkedList<>();
            ResolvedTarget t = new ResolvedTarget();
            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", false));
            result.add(new Instance(t, "faedbb0a-2273-4cb4-a659-bd31331f7daf:1", "http://localhost:1234", false));
            t = new ResolvedTarget();
            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", false));
            if (applicationIdFilter != null) {
                for (Iterator<Instance> it = result.iterator(); it.hasNext(); ) {
                    Instance instance = it.next();
                    if (!applicationIdFilter.test(instance.getApplicationId()))
                        it.remove();
                }
            }
            if (instanceFilter != null) {
                for (Iterator<Instance> it = result.iterator(); it.hasNext(); ) {
                    Instance instance = it.next();
                    if (!instanceFilter.test(instance))
                        it.remove();
                }
            }
            return result;
        }
    };
}
Also used : AppInstanceScanner(org.cloudfoundry.promregator.scanner.AppInstanceScanner) Instance(org.cloudfoundry.promregator.scanner.Instance) LinkedList(java.util.LinkedList) List(java.util.List) ResolvedTarget(org.cloudfoundry.promregator.scanner.ResolvedTarget) Nullable(javax.annotation.Nullable) LinkedList(java.util.LinkedList) Predicate(java.util.function.Predicate) Bean(org.springframework.context.annotation.Bean)

Aggregations

ResolvedTarget (org.cloudfoundry.promregator.scanner.ResolvedTarget)7 Instance (org.cloudfoundry.promregator.scanner.Instance)6 LinkedList (java.util.LinkedList)3 Nullable (javax.annotation.Nullable)3 AbstractMetricFamilySamplesEnricher (org.cloudfoundry.promregator.rewrite.AbstractMetricFamilySamplesEnricher)3 CFAllLabelsMetricFamilySamplesEnricher (org.cloudfoundry.promregator.rewrite.CFAllLabelsMetricFamilySamplesEnricher)3 Gauge (io.prometheus.client.Gauge)2 List (java.util.List)2 Predicate (java.util.function.Predicate)2 MetricsFetcherMetrics (org.cloudfoundry.promregator.fetcher.MetricsFetcherMetrics)2 NullMetricFamilySamplesEnricher (org.cloudfoundry.promregator.rewrite.NullMetricFamilySamplesEnricher)2 AppInstanceScanner (org.cloudfoundry.promregator.scanner.AppInstanceScanner)2 Test (org.junit.jupiter.api.Test)2 Bean (org.springframework.context.annotation.Bean)2 MetricFamilySamples (io.prometheus.client.Collector.MetricFamilySamples)1 ArrayList (java.util.ArrayList)1 AuthenticationEnricher (org.cloudfoundry.promregator.auth.AuthenticationEnricher)1 Target (org.cloudfoundry.promregator.config.Target)1 CFMetricsFetcher (org.cloudfoundry.promregator.fetcher.CFMetricsFetcher)1 CFMetricsFetcherConfig (org.cloudfoundry.promregator.fetcher.CFMetricsFetcherConfig)1