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

com.yahoo.vespa.config.server.metrics.SearchNodeMetricsRetriever 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.SearchNodeMetricsResponse;
import java.net.URI;
import java.util.Collection;
import java.util.function.Predicate;

public class SearchNodeMetricsRetriever {

    private final ClusterSearchNodeMetricsRetriever metricsRetriever;

    public SearchNodeMetricsRetriever() {
        this( new ClusterSearchNodeMetricsRetriever());
    }

    public SearchNodeMetricsRetriever(ClusterSearchNodeMetricsRetriever metricsRetriever) {
        this.metricsRetriever = metricsRetriever;
    }

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

    private static Collection getHostsOfApplication(Application application) {
        return application.getModel().getHosts().stream()
                .filter(host -> host.getServices().stream().anyMatch(isSearchNode()))
                .map(HostInfo::getHostname)
                .map(SearchNodeMetricsRetriever::createMetricsProxyURI)
                .toList();
    }

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

    private static URI createMetricsProxyURI(String hostname) {
        return URI.create("http://" + hostname + ":19092/metrics/v2/values");
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy