All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.vespa.config.server.metrics.DeploymentMetricsRetriever Maven / Gradle / Ivy

There is a newer version: 8.441.21
Show newest version
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.metrics;

import com.yahoo.config.model.api.HostInfo;
import com.yahoo.config.model.api.ServiceInfo;
import com.yahoo.vespa.config.server.application.Application;
import com.yahoo.vespa.config.server.http.v2.response.DeploymentMetricsResponse;
import java.net.URI;
import java.util.Collection;
import java.util.function.Predicate;

/**
 * Finds all hosts we want to fetch metrics for, generates the appropriate URIs
 * and returns the generated MetricsResponse.
 *
 * @author olaa
 */
public class DeploymentMetricsRetriever {

    private final ClusterDeploymentMetricsRetriever metricsRetriever;

    public DeploymentMetricsRetriever() {
        this(new ClusterDeploymentMetricsRetriever());
    }

    public DeploymentMetricsRetriever(ClusterDeploymentMetricsRetriever metricsRetriever) {
        this.metricsRetriever = metricsRetriever;
    }

    public DeploymentMetricsResponse getMetrics(Application application) {
        var hosts = getHostsOfApplication(application);
        var clusterMetrics = metricsRetriever.requestMetricsGroupedByCluster(hosts);
        return new DeploymentMetricsResponse(application.getId(), clusterMetrics);
    }

    private static Collection getHostsOfApplication(Application application) {
        return application.getModel().getHosts().stream()
                .filter(host -> host.getServices().stream().noneMatch(isLogserver()))
                .map(HostInfo::getHostname)
                .map(DeploymentMetricsRetriever::createMetricsProxyURI)
                .toList();

    }

    private static Predicate isLogserver() {
        return serviceInfo -> serviceInfo.getServiceType().equalsIgnoreCase("logserver");
    }

    private static URI createMetricsProxyURI(String hostname) {
        return URI.create("http://" + hostname + ":19092/metrics/v1/values?consumer=Vespa");
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy