Search in sources :

Example 1 with MetricsFetcherSimulator

use of org.cloudfoundry.promregator.fetcher.MetricsFetcherSimulator 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)

Aggregations

Gauge (io.prometheus.client.Gauge)1 LinkedList (java.util.LinkedList)1 AuthenticationEnricher (org.cloudfoundry.promregator.auth.AuthenticationEnricher)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