Search in sources :

Example 1 with AuthenticationEnricher

use of org.cloudfoundry.promregator.auth.AuthenticationEnricher 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.debug(String.format("Creating Metrics Fetcher for instance %s", instance.getInstanceId()));
        ResolvedTarget 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;
        }
        String[] ownTelemetryLabelValues = this.determineOwnTelemetryLabelValues(orgName, spaceName, appName, instance.getInstanceId());
        MetricsFetcherMetrics mfm = new MetricsFetcherMetrics(ownTelemetryLabelValues, this.recordRequestLatency);
        final boolean labelEnrichmentEnabled = this.isLabelEnrichmentEnabled();
        /*
			 * Warning! the gauge "up" is a very special beast!
			 * As it is always transferred along the other metrics (it's not a promregator-own metric!), it must always
			 * follow the same labels as the other metrics which are scraped
			 */
        Gauge.Child upChild = null;
        AbstractMetricFamilySamplesEnricher mfse = null;
        if (labelEnrichmentEnabled) {
            mfse = new CFAllLabelsMetricFamilySamplesEnricher(orgName, spaceName, appName, instance.getInstanceId());
        } else {
            mfse = new NullMetricFamilySamplesEnricher();
        }
        upChild = this.up.labels(mfse.getEnrichedLabelValues(new LinkedList<>()).toArray(new String[0]));
        AuthenticationEnricher ae = this.authenticatorController.getAuthenticationEnricherByTarget(instance.getTarget().getOriginalTarget());
        MetricsFetcher mf = null;
        if (this.simulationMode) {
            mf = new MetricsFetcherSimulator(accessURL, ae, mfse, mfm, upChild);
        } else {
            CFMetricsFetcherConfig cfmfConfig = new CFMetricsFetcherConfig();
            cfmfConfig.setAuthenticationEnricher(ae);
            cfmfConfig.setMetricFamilySamplesEnricher(mfse);
            cfmfConfig.setMetricsFetcherMetrics(mfm);
            cfmfConfig.setUpChild(upChild);
            cfmfConfig.setPromregatorInstanceIdentifier(this.promregatorInstanceIdentifier);
            cfmfConfig.setConnectionTimeoutInMillis(this.fetcherConnectionTimeout);
            cfmfConfig.setSocketReadTimeoutInMillis(this.fetcherSocketReadTimeout);
            this.provideProxyConfiguration(cfmfConfig);
            mf = new CFMetricsFetcher(accessURL, instance.getInstanceId(), cfmfConfig, instance.isInternal());
        }
        callablesList.add(mf);
    }
    return callablesList;
}
Also used : MetricsFetcherMetrics(org.cloudfoundry.promregator.fetcher.MetricsFetcherMetrics) CFMetricsFetcherConfig(org.cloudfoundry.promregator.fetcher.CFMetricsFetcherConfig) CFMetricsFetcher(org.cloudfoundry.promregator.fetcher.CFMetricsFetcher) Instance(org.cloudfoundry.promregator.scanner.Instance) ResolvedTarget(org.cloudfoundry.promregator.scanner.ResolvedTarget) AbstractMetricFamilySamplesEnricher(org.cloudfoundry.promregator.rewrite.AbstractMetricFamilySamplesEnricher) LinkedList(java.util.LinkedList) Gauge(io.prometheus.client.Gauge) AuthenticationEnricher(org.cloudfoundry.promregator.auth.AuthenticationEnricher) MetricsFetcherSimulator(org.cloudfoundry.promregator.fetcher.MetricsFetcherSimulator) CFAllLabelsMetricFamilySamplesEnricher(org.cloudfoundry.promregator.rewrite.CFAllLabelsMetricFamilySamplesEnricher) MetricsFetcher(org.cloudfoundry.promregator.fetcher.MetricsFetcher) CFMetricsFetcher(org.cloudfoundry.promregator.fetcher.CFMetricsFetcher) NullMetricFamilySamplesEnricher(org.cloudfoundry.promregator.rewrite.NullMetricFamilySamplesEnricher)

Example 2 with AuthenticationEnricher

use of org.cloudfoundry.promregator.auth.AuthenticationEnricher in project promregator by promregator.

the class PromregatorApplication method authenticationEnricher.

@Bean
public AuthenticationEnricher authenticationEnricher(PromregatorConfiguration promregatorConfiguration) {
    AuthenticationEnricher ae = null;
    String type = promregatorConfiguration.getAuthenticator().getType();
    if ("OAuth2XSUAA".equalsIgnoreCase(type)) {
        ae = new OAuth2XSUAAEnricher(promregatorConfiguration.getAuthenticator().getOauth2xsuaa());
    } else if ("none".equalsIgnoreCase(type) || "null".equalsIgnoreCase(type)) {
        ae = new NullEnricher();
    } else if ("basic".equalsIgnoreCase(type)) {
        ae = new BasicAuthenticationEnricher(promregatorConfiguration.getAuthenticator().getBasic());
    } else {
        log.warn(String.format("Authenticator type %s is unknown; skipping", type));
    }
    return ae;
}
Also used : OAuth2XSUAAEnricher(org.cloudfoundry.promregator.auth.OAuth2XSUAAEnricher) NullEnricher(org.cloudfoundry.promregator.auth.NullEnricher) BasicAuthenticationEnricher(org.cloudfoundry.promregator.auth.BasicAuthenticationEnricher) AuthenticationEnricher(org.cloudfoundry.promregator.auth.AuthenticationEnricher) BasicAuthenticationEnricher(org.cloudfoundry.promregator.auth.BasicAuthenticationEnricher) Bean(org.springframework.context.annotation.Bean)

Aggregations

AuthenticationEnricher (org.cloudfoundry.promregator.auth.AuthenticationEnricher)2 Gauge (io.prometheus.client.Gauge)1 LinkedList (java.util.LinkedList)1 BasicAuthenticationEnricher (org.cloudfoundry.promregator.auth.BasicAuthenticationEnricher)1 NullEnricher (org.cloudfoundry.promregator.auth.NullEnricher)1 OAuth2XSUAAEnricher (org.cloudfoundry.promregator.auth.OAuth2XSUAAEnricher)1 CFMetricsFetcher (org.cloudfoundry.promregator.fetcher.CFMetricsFetcher)1 CFMetricsFetcherConfig (org.cloudfoundry.promregator.fetcher.CFMetricsFetcherConfig)1 MetricsFetcher (org.cloudfoundry.promregator.fetcher.MetricsFetcher)1 MetricsFetcherMetrics (org.cloudfoundry.promregator.fetcher.MetricsFetcherMetrics)1 MetricsFetcherSimulator (org.cloudfoundry.promregator.fetcher.MetricsFetcherSimulator)1 AbstractMetricFamilySamplesEnricher (org.cloudfoundry.promregator.rewrite.AbstractMetricFamilySamplesEnricher)1 CFAllLabelsMetricFamilySamplesEnricher (org.cloudfoundry.promregator.rewrite.CFAllLabelsMetricFamilySamplesEnricher)1 NullMetricFamilySamplesEnricher (org.cloudfoundry.promregator.rewrite.NullMetricFamilySamplesEnricher)1 Instance (org.cloudfoundry.promregator.scanner.Instance)1 ResolvedTarget (org.cloudfoundry.promregator.scanner.ResolvedTarget)1 Bean (org.springframework.context.annotation.Bean)1