diff options
Diffstat (limited to 'service-monitor/src/main/java/com/yahoo')
10 files changed, 189 insertions, 43 deletions
diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/ServiceStatusProvider.java b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/ServiceStatusProvider.java new file mode 100644 index 00000000000..35003313775 --- /dev/null +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/ServiceStatusProvider.java @@ -0,0 +1,19 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.service.monitor;// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.vespa.applicationmodel.ClusterId; +import com.yahoo.vespa.applicationmodel.ConfigId; +import com.yahoo.vespa.applicationmodel.ServiceStatus; +import com.yahoo.vespa.applicationmodel.ServiceType; + +/** + * @author hakon + */ +public interface ServiceStatusProvider { + /** Get the {@link ServiceStatus} of a particular service. */ + ServiceStatus getStatus(ApplicationId applicationId, + ClusterId clusterId, + ServiceType serviceType, + ConfigId configId); +} diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/SlobrokMonitorManager.java b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/SlobrokApi.java index 9cffa1192be..dff605b888d 100644 --- a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/SlobrokMonitorManager.java +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/SlobrokApi.java @@ -3,23 +3,13 @@ package com.yahoo.vespa.service.monitor; import com.yahoo.config.provision.ApplicationId; import com.yahoo.jrt.slobrok.api.Mirror; -import com.yahoo.vespa.applicationmodel.ConfigId; -import com.yahoo.vespa.applicationmodel.ServiceStatus; -import com.yahoo.vespa.applicationmodel.ServiceType; import java.util.List; -public interface SlobrokMonitorManager { +public interface SlobrokApi extends ServiceStatusProvider { /** * Get all Slobrok entries that has a name matching pattern as described in * Mirror::lookup. */ List<Mirror.Entry> lookup(ApplicationId application, String pattern); - - /** - * Query the ServiceMonitorStatus of a particular service. - */ - ServiceStatus getStatus(ApplicationId applicationId, - ServiceType serviceType, - ConfigId configId); } diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/HealthMonitorManager.java b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/HealthMonitorManager.java new file mode 100644 index 00000000000..160a49594b8 --- /dev/null +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/HealthMonitorManager.java @@ -0,0 +1,37 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.service.monitor.internal; + +import com.yahoo.config.model.api.ApplicationInfo; +import com.yahoo.config.model.api.SuperModel; +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.vespa.applicationmodel.ClusterId; +import com.yahoo.vespa.applicationmodel.ConfigId; +import com.yahoo.vespa.applicationmodel.ServiceStatus; +import com.yahoo.vespa.applicationmodel.ServiceType; + +/** + * @author hakon + */ +public class HealthMonitorManager implements MonitorManager { + HealthMonitorManager() {} + + @Override + public void applicationActivated(SuperModel superModel, ApplicationInfo application) { + } + + @Override + public void applicationRemoved(SuperModel superModel, ApplicationId id) { + } + + @Override + public ServiceStatus getStatus(ApplicationId applicationId, ClusterId clusterId, ServiceType serviceType, ConfigId configId) { + // TODO: Do proper health check + if (ZoneApplication.isNodeAdminService(applicationId, clusterId, serviceType)) { + return ServiceStatus.UP; + } + + throw new IllegalArgumentException("Health monitoring not implemented for application " + + applicationId.toShortString() + ", cluster " + clusterId.s() + ", serviceType " + + serviceType); + } +} diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/ModelGenerator.java b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/ModelGenerator.java index 961d5701901..ca70b18439b 100644 --- a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/ModelGenerator.java +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/ModelGenerator.java @@ -20,7 +20,7 @@ import com.yahoo.vespa.applicationmodel.ServiceStatus; import com.yahoo.vespa.applicationmodel.ServiceType; import com.yahoo.vespa.applicationmodel.TenantId; import com.yahoo.vespa.service.monitor.ServiceModel; -import com.yahoo.vespa.service.monitor.SlobrokMonitorManager; +import com.yahoo.vespa.service.monitor.ServiceStatusProvider; import java.util.HashMap; import java.util.HashSet; @@ -44,7 +44,7 @@ public class ModelGenerator { SuperModel superModel, Zone zone, List<String> configServerHosts, - SlobrokMonitorManager slobrokMonitorManager) { + ServiceStatusProvider serviceStatusProvider) { Map<ApplicationInstanceReference, ApplicationInstance> applicationInstances = new HashMap<>(); for (ApplicationInfo applicationInfo : superModel.getAllApplicationInfos()) { @@ -52,7 +52,7 @@ public class ModelGenerator { ApplicationInstance applicationInstance = toApplicationInstance( applicationInfo, zone, - slobrokMonitorManager); + serviceStatusProvider); applicationInstances.put(applicationInstance.reference(), applicationInstance); } @@ -70,7 +70,7 @@ public class ModelGenerator { ApplicationInstance toApplicationInstance( ApplicationInfo applicationInfo, Zone zone, - SlobrokMonitorManager slobrokMonitorManager) { + ServiceStatusProvider serviceStatusProvider) { Map<ServiceClusterKey, Set<ServiceInstance>> groupedServiceInstances = new HashMap<>(); for (HostInfo host : applicationInfo.getModel().getHosts()) { @@ -80,9 +80,10 @@ public class ModelGenerator { ServiceInstance serviceInstance = toServiceInstance( applicationInfo.getApplicationId(), + serviceClusterKey.clusterId(), serviceInfo, hostName, - slobrokMonitorManager); + serviceStatusProvider); if (!groupedServiceInstances.containsKey(serviceClusterKey)) { groupedServiceInstances.put(serviceClusterKey, new HashSet<>()); @@ -114,28 +115,33 @@ public class ModelGenerator { return applicationInstance; } - ServiceClusterKey toServiceClusterKey(ServiceInfo serviceInfo) { - ClusterId clusterId = new ClusterId(serviceInfo.getProperty(CLUSTER_ID_PROPERTY_NAME).orElse("")); + static ClusterId getClusterId(ServiceInfo serviceInfo) { + return new ClusterId(serviceInfo.getProperty(CLUSTER_ID_PROPERTY_NAME).orElse("")); + } + + private ServiceClusterKey toServiceClusterKey(ServiceInfo serviceInfo) { + ClusterId clusterId = getClusterId(serviceInfo); ServiceType serviceType = toServiceType(serviceInfo); return new ServiceClusterKey(clusterId, serviceType); } - ServiceInstance toServiceInstance( + private ServiceInstance toServiceInstance( ApplicationId applicationId, + ClusterId clusterId, ServiceInfo serviceInfo, HostName hostName, - SlobrokMonitorManager slobrokMonitorManager) { + ServiceStatusProvider serviceStatusProvider) { ConfigId configId = new ConfigId(serviceInfo.getConfigId()); - ServiceStatus status = slobrokMonitorManager.getStatus( + ServiceStatus status = serviceStatusProvider.getStatus( applicationId, - toServiceType(serviceInfo), - configId); + clusterId, + toServiceType(serviceInfo), configId); return new ServiceInstance(configId, hostName, status); } - ApplicationInstanceId toApplicationInstanceId(ApplicationInfo applicationInfo, Zone zone) { + private ApplicationInstanceId toApplicationInstanceId(ApplicationInfo applicationInfo, Zone zone) { return new ApplicationInstanceId(String.format("%s:%s:%s:%s", applicationInfo.getApplicationId().application().value(), zone.environment().value(), @@ -143,7 +149,7 @@ public class ModelGenerator { applicationInfo.getApplicationId().instance().value())); } - ServiceType toServiceType(ServiceInfo serviceInfo) { + private ServiceType toServiceType(ServiceInfo serviceInfo) { return new ServiceType(serviceInfo.getServiceType()); } } diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/MonitorManager.java b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/MonitorManager.java new file mode 100644 index 00000000000..49863672c43 --- /dev/null +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/MonitorManager.java @@ -0,0 +1,11 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.service.monitor.internal;// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +import com.yahoo.config.model.api.SuperModelListener; +import com.yahoo.vespa.service.monitor.ServiceStatusProvider; + +/** + * @author hakon + */ +public interface MonitorManager extends SuperModelListener, ServiceStatusProvider { +} diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/ServiceMonitorImpl.java b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/ServiceMonitorImpl.java index 282a0797912..b2b6538fe6c 100644 --- a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/ServiceMonitorImpl.java +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/ServiceMonitorImpl.java @@ -15,42 +15,41 @@ import com.yahoo.vespa.service.monitor.ServiceMonitor; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.logging.Logger; import java.util.stream.Collectors; public class ServiceMonitorImpl implements ServiceMonitor { - private static final Logger logger = Logger.getLogger(ServiceMonitorImpl.class.getName()); - - private final Zone zone; - private final List<String> configServerHosts; private final ServiceModelCache serviceModelCache; @Inject public ServiceMonitorImpl(SuperModelProvider superModelProvider, ConfigserverConfig configserverConfig, SlobrokMonitorManagerImpl slobrokMonitorManager, + HealthMonitorManager healthMonitorManager, Metric metric, Timer timer) { - this.zone = superModelProvider.getZone(); - this.configServerHosts = toConfigServerList(configserverConfig); + Zone zone = superModelProvider.getZone(); + List<String> configServerHosts = toConfigServerList(configserverConfig); ServiceMonitorMetrics metrics = new ServiceMonitorMetrics(metric, timer); - SuperModelListenerImpl superModelListener = new SuperModelListenerImpl( + UnionMonitorManager monitorManager = new UnionMonitorManager( slobrokMonitorManager, + healthMonitorManager, + configserverConfig); + + SuperModelListenerImpl superModelListener = new SuperModelListenerImpl( + monitorManager, metrics, new ModelGenerator(), zone, configServerHosts); superModelListener.start(superModelProvider); - serviceModelCache = new ServiceModelCache( - () -> superModelListener.get(), - timer); + serviceModelCache = new ServiceModelCache(superModelListener, timer); } private List<String> toConfigServerList(ConfigserverConfig configserverConfig) { if (configserverConfig.multitenant()) { return configserverConfig.zookeeperserver().stream() - .map(server -> server.hostname()) + .map(ConfigserverConfig.Zookeeperserver::hostname) .collect(Collectors.toList()); } diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/SlobrokMonitorManagerImpl.java b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/SlobrokMonitorManagerImpl.java index 801f4b05079..b96364bf95e 100644 --- a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/SlobrokMonitorManagerImpl.java +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/SlobrokMonitorManagerImpl.java @@ -8,10 +8,11 @@ import com.yahoo.config.model.api.SuperModelListener; import com.yahoo.config.provision.ApplicationId; import com.yahoo.jrt.slobrok.api.Mirror; import com.yahoo.log.LogLevel; +import com.yahoo.vespa.applicationmodel.ClusterId; import com.yahoo.vespa.applicationmodel.ConfigId; import com.yahoo.vespa.applicationmodel.ServiceStatus; import com.yahoo.vespa.applicationmodel.ServiceType; -import com.yahoo.vespa.service.monitor.SlobrokMonitorManager; +import com.yahoo.vespa.service.monitor.SlobrokApi; import java.util.HashMap; import java.util.List; @@ -19,7 +20,7 @@ import java.util.Optional; import java.util.function.Supplier; import java.util.logging.Logger; -public class SlobrokMonitorManagerImpl implements SuperModelListener, SlobrokMonitorManager { +public class SlobrokMonitorManagerImpl implements SuperModelListener, SlobrokApi, MonitorManager { private static final Logger logger = Logger.getLogger(SlobrokMonitorManagerImpl.class.getName()); @@ -30,7 +31,7 @@ public class SlobrokMonitorManagerImpl implements SuperModelListener, SlobrokMon @Inject public SlobrokMonitorManagerImpl() { - this(() -> new SlobrokMonitor()); + this(SlobrokMonitor::new); } SlobrokMonitorManagerImpl(Supplier<SlobrokMonitor> slobrokMonitorFactory) { @@ -74,7 +75,7 @@ public class SlobrokMonitorManagerImpl implements SuperModelListener, SlobrokMon @Override public ServiceStatus getStatus(ApplicationId applicationId, - ServiceType serviceType, + ClusterId clusterId, ServiceType serviceType, ConfigId configId) { Optional<String> slobrokServiceName = findSlobrokServiceName(serviceType, configId); if (slobrokServiceName.isPresent()) { diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/SuperModelListenerImpl.java b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/SuperModelListenerImpl.java index 82d55cd05d7..5e309d3c18d 100644 --- a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/SuperModelListenerImpl.java +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/SuperModelListenerImpl.java @@ -24,10 +24,10 @@ public class SuperModelListenerImpl implements SuperModelListener, Supplier<Serv // superModel and slobrokMonitorManager are always updated together // and atomically using this monitor. private final Object monitor = new Object(); - private final SlobrokMonitorManagerImpl slobrokMonitorManager; + private final MonitorManager slobrokMonitorManager; private SuperModel superModel; - SuperModelListenerImpl(SlobrokMonitorManagerImpl slobrokMonitorManager, + SuperModelListenerImpl(MonitorManager slobrokMonitorManager, ServiceMonitorMetrics metrics, ModelGenerator modelGenerator, Zone zone, diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/UnionMonitorManager.java b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/UnionMonitorManager.java new file mode 100644 index 00000000000..0bb4dea5a94 --- /dev/null +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/UnionMonitorManager.java @@ -0,0 +1,57 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.service.monitor.internal; + +import com.yahoo.cloud.config.ConfigserverConfig; +import com.yahoo.config.model.api.ApplicationInfo; +import com.yahoo.config.model.api.SuperModel; +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.vespa.applicationmodel.ClusterId; +import com.yahoo.vespa.applicationmodel.ConfigId; +import com.yahoo.vespa.applicationmodel.ServiceStatus; +import com.yahoo.vespa.applicationmodel.ServiceType; + +/** + * @author hakon + */ +public class UnionMonitorManager implements MonitorManager { + private final SlobrokMonitorManagerImpl slobrokMonitorManager; + private final HealthMonitorManager healthMonitorManager; + private final ConfigserverConfig configserverConfig; + + UnionMonitorManager(SlobrokMonitorManagerImpl slobrokMonitorManager, + HealthMonitorManager healthMonitorManager, + ConfigserverConfig configserverConfig) { + this.slobrokMonitorManager = slobrokMonitorManager; + this.healthMonitorManager = healthMonitorManager; + this.configserverConfig = configserverConfig; + } + + @Override + public ServiceStatus getStatus(ApplicationId applicationId, + ClusterId clusterId, + ServiceType serviceType, + ConfigId configId) { + MonitorManager monitorManager = useHealth(applicationId, clusterId, serviceType) ? + healthMonitorManager : + slobrokMonitorManager; + + return monitorManager.getStatus(applicationId, clusterId, serviceType, configId); + } + + @Override + public void applicationActivated(SuperModel superModel, ApplicationInfo application) { + slobrokMonitorManager.applicationActivated(superModel, application); + healthMonitorManager.applicationActivated(superModel, application); + } + + @Override + public void applicationRemoved(SuperModel superModel, ApplicationId id) { + slobrokMonitorManager.applicationRemoved(superModel, id); + healthMonitorManager.applicationRemoved(superModel, id); + } + + private boolean useHealth(ApplicationId applicationId, ClusterId clusterId, ServiceType serviceType) { + return !configserverConfig.nodeAdminInContainer() && + ZoneApplication.isNodeAdminService(applicationId, clusterId, serviceType); + } +} diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/ZoneApplication.java b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/ZoneApplication.java new file mode 100644 index 00000000000..f7097e867df --- /dev/null +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/internal/ZoneApplication.java @@ -0,0 +1,26 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.service.monitor.internal; + +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.vespa.applicationmodel.ClusterId; +import com.yahoo.vespa.applicationmodel.ServiceType; + +import java.util.Objects; + +/** + * @author hakon + */ +public class ZoneApplication { + private ZoneApplication() {} + + static final ApplicationId ZONE_APPLICATION_ID = + ApplicationId.from("hosted-vespa", "routing", "default"); + + static boolean isNodeAdminService(ApplicationId applicationId, + ClusterId clusterId, + ServiceType serviceType) { + return Objects.equals(applicationId, ZONE_APPLICATION_ID) && + Objects.equals(serviceType, ServiceType.CONTAINER) && + Objects.equals(clusterId, ClusterId.NODE_ADMIN); + } +} |