diff options
author | Valerij Fredriksen <valerijf@verizonmedia.com> | 2019-07-04 11:10:50 +0200 |
---|---|---|
committer | Valerij Fredriksen <valerijf@verizonmedia.com> | 2019-07-04 11:24:56 +0200 |
commit | 36d91d1cf1c30b6e0e8f6aad4c449e2d75fcb3aa (patch) | |
tree | 60838f37ec800154d497568f891f1a0c40dd4c27 /node-admin/src/main | |
parent | 62bacdeb10990055935375bb76e76e2f34e8e214 (diff) |
Remove metrics check config writer code
Diffstat (limited to 'node-admin/src/main')
4 files changed, 1 insertions, 243 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainer.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainer.java index 26e4dcda88e..167ca15bdbf 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainer.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainer.java @@ -3,17 +3,14 @@ package com.yahoo.vespa.hosted.node.admin.maintenance; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import com.yahoo.config.provision.NodeType; import com.yahoo.log.LogLevel; import com.yahoo.vespa.hosted.dockerapi.Container; import com.yahoo.vespa.hosted.node.admin.component.TaskContext; -import com.yahoo.vespa.hosted.node.admin.docker.DockerOperations; import com.yahoo.vespa.hosted.node.admin.maintenance.coredump.CoredumpHandler; import com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentContext; import com.yahoo.vespa.hosted.node.admin.task.util.file.FileFinder; import com.yahoo.vespa.hosted.node.admin.task.util.file.UnixPath; import com.yahoo.vespa.hosted.node.admin.task.util.process.Terminal; -import com.yahoo.vespa.hosted.node.admin.util.SecretAgentCheckConfig; import java.nio.file.Files; import java.nio.file.Path; @@ -22,11 +19,8 @@ import java.time.Duration; import java.time.Instant; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; import java.util.Optional; import java.util.concurrent.TimeUnit; @@ -35,7 +29,6 @@ import java.util.regex.Pattern; import static com.yahoo.vespa.hosted.node.admin.task.util.file.FileFinder.nameMatches; import static com.yahoo.vespa.hosted.node.admin.task.util.file.FileFinder.olderThan; -import static com.yahoo.vespa.hosted.node.admin.util.SecretAgentCheckConfig.nodeTypeToRole; import static com.yahoo.yolean.Exceptions.uncheck; /** @@ -47,7 +40,6 @@ public class StorageMaintainer { .ofPattern("yyyyMMddHHmmss").withZone(ZoneOffset.UTC); private final Terminal terminal; - private final DockerOperations dockerOperations; private final CoredumpHandler coredumpHandler; private final Path archiveContainerStoragePath; @@ -57,134 +49,12 @@ public class StorageMaintainer { .expireAfterWrite(5, TimeUnit.MINUTES) .build(); - public StorageMaintainer(Terminal terminal, DockerOperations dockerOperations, CoredumpHandler coredumpHandler, Path archiveContainerStoragePath) { + public StorageMaintainer(Terminal terminal, CoredumpHandler coredumpHandler, Path archiveContainerStoragePath) { this.terminal = terminal; - this.dockerOperations = dockerOperations; this.coredumpHandler = coredumpHandler; this.archiveContainerStoragePath = archiveContainerStoragePath; } - public void writeMetricsConfig(NodeAgentContext context) { - List<SecretAgentCheckConfig> configs = new ArrayList<>(); - Map<String, Object> tags = generateTags(context); - - // host-life - Path hostLifeCheckPath = context.pathInNodeUnderVespaHome("libexec/yms/yms_check_host_life"); - configs.add(new SecretAgentCheckConfig("host-life", 60, hostLifeCheckPath).withTags(tags)); - - // coredumps (except for the done coredumps which is handled by the host) - Path coredumpCheckPath = context.pathInNodeUnderVespaHome("libexec/yms/yms_check_coredumps"); - configs.add(new SecretAgentCheckConfig("system-coredumps-processing", 300, coredumpCheckPath, - "--application", "system-coredumps-processing", - "--lastmin", "129600", - "--crit", "1", - "--coredir", context.pathInNodeUnderVespaHome("var/crash/processing").toString()) - .withTags(tags)); - - // athenz certificate check - Path athenzCertExpiryCheckPath = context.pathInNodeUnderVespaHome("libexec64/yms/yms_check_athenz_certs"); - configs.add(new SecretAgentCheckConfig("athenz-certificate-expiry", 60, athenzCertExpiryCheckPath, - "--threshold", "20") - .withRunAsUser("root") - .withTags(tags)); - - if (context.nodeType() != NodeType.config) { - // vespa-health - Path vespaHealthCheckPath = context.pathInNodeUnderVespaHome("libexec/yms/yms_check_vespa_health"); - configs.add(new SecretAgentCheckConfig("vespa-health", 60, vespaHealthCheckPath, "all") - .withRunAsUser(context.vespaUser()) - .withTags(tags)); - - // vespa - Path vespaCheckPath = context.pathInNodeUnderVespaHome("libexec/yms/yms_check_vespa"); - SecretAgentCheckConfig vespaSchedule = new SecretAgentCheckConfig("vespa", 60, vespaCheckPath, "all"); - vespaSchedule.withRunAsUser(context.vespaUser()); - if (isConfigserverLike(context.nodeType())) { - Map<String, Object> tagsWithoutNameSpace = new LinkedHashMap<>(tags); - tagsWithoutNameSpace.remove("namespace"); - vespaSchedule.withTags(tagsWithoutNameSpace); - } - configs.add(vespaSchedule); - } - - if (context.nodeType() == NodeType.config || context.nodeType() == NodeType.controller) { - - // configserver/controller - Path configServerNewCheckPath = Paths.get("/usr/bin/curl"); - configs.add(new SecretAgentCheckConfig(nodeTypeToRole(context.nodeType()), 60, configServerNewCheckPath, - "-s", "localhost:19071/yamas-metrics") - .withTags(tags)); - - //zkbackupage - Path zkbackupCheckPath = context.pathInNodeUnderVespaHome("libexec/yamas2/yms_check_file_age.py"); - configs.add(new SecretAgentCheckConfig("zkbackupage", 300, zkbackupCheckPath, - "-f", context.pathInNodeUnderVespaHome("var/vespa-hosted/zkbackup.stat").toString(), - "-m", "150", - "-a", "config-zkbackupage") - .withTags(tags)); - - String appName = nodeTypeToRole(context.nodeType()) + "-logd"; - Path logdCheckPath = context.pathInNodeUnderVespaHome("libexec/yms/convert-state-metrics-2-yamas.py"); - configs.add(new SecretAgentCheckConfig(appName, 60, logdCheckPath, - appName, "http://localhost:19089/state/v1/metrics") - .withTags(tags)); - } - - if (context.nodeType() == NodeType.proxy) { - //routing-configage - Path routingAgeCheckPath = context.pathInNodeUnderVespaHome("libexec/yamas2/yms_check_file_age.py"); - configs.add(new SecretAgentCheckConfig("routing-configage", 60, routingAgeCheckPath, - "-f", context.pathInNodeUnderVespaHome("var/vespa-hosted/routing/nginx.conf.tmp").toString(), - "-m", "1", - "-a", "routing-configage", - "--ignore_file_not_found") - .withTags(tags)); - - //ssl-check - Path sslCheckPath = context.pathInNodeUnderVespaHome("libexec/yms/yms_check_ssl_status"); - configs.add(new SecretAgentCheckConfig("ssl-status", 300, sslCheckPath, - "-e", "localhost", - "-p", "4443", - "-t", "30") - .withTags(tags)); - } - - // Write config and restart yamas-agent - Path yamasAgentFolder = context.pathOnHostFromPathInNode("/etc/yamas-agent"); - configs.forEach(s -> uncheck(() -> s.writeTo(yamasAgentFolder))); - dockerOperations.executeCommandInContainerAsRoot(context, "service", "yamas-agent", "restart"); - } - - private Map<String, Object> generateTags(NodeAgentContext context) { - Map<String, String> tags = new LinkedHashMap<>(); - tags.put("namespace", "Vespa"); - tags.put("role", nodeTypeToRole(context.node().type())); - tags.put("zone", context.zone().getId().value()); - context.node().currentVespaVersion().ifPresent(version -> tags.put("vespaVersion", version.toFullString())); - - if (! isConfigserverLike(context.nodeType())) { - tags.put("state", context.node().state().toString()); - context.node().parentHostname().ifPresent(parent -> tags.put("parentHostname", parent)); - context.node().owner().ifPresent(owner -> { - tags.put("tenantName", owner.tenant()); - tags.put("app", owner.application() + "." + owner.instance()); - tags.put("applicationName", owner.application()); - tags.put("instanceName", owner.instance()); - tags.put("applicationId", owner.tenant() + "." + owner.application() + "." + owner.instance()); - }); - context.node().membership().ifPresent(membership -> { - tags.put("clustertype", membership.clusterType()); - tags.put("clusterid", membership.clusterId()); - }); - } - - return Collections.unmodifiableMap(tags); - } - - private boolean isConfigserverLike(NodeType nodeType) { - return nodeType == NodeType.config || nodeType == NodeType.controller; - } - public Optional<Long> getDiskUsageFor(NodeAgentContext context) { try { Path path = context.pathOnHostFromPathInNode("/"); diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java index 901a315ffb6..77c08133e82 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java @@ -399,12 +399,6 @@ public class NodeAgentImpl implements NodeAgent { currentRestartGeneration.map(current -> current < node.currentRestartGeneration().get()).orElse(false)) currentRestartGeneration = node.currentRestartGeneration(); - // Every time the node spec changes, we should clear the metrics for this container as the dimensions - // will change and we will be reporting duplicate metrics. - if (container.map(c -> c.state.isRunning()).orElse(false)) { - storageMaintainer.writeMetricsConfig(context); - } - lastNode = node; } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/SecretAgentCheckConfig.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/SecretAgentCheckConfig.java deleted file mode 100644 index cdf67871a1a..00000000000 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/SecretAgentCheckConfig.java +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.hosted.node.admin.util; - -import com.yahoo.config.provision.NodeType; -import com.yahoo.vespa.hosted.node.admin.task.util.file.FileWriter; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * Helper class to generate and write the secret-agent check config files. - * - * @author freva - */ -public class SecretAgentCheckConfig { - private final String id; - private final int interval; - private final Path checkExecutable; - private final String[] arguments; - private String user = "nobody"; - private final Map<String, Object> tags = new LinkedHashMap<>(); - - public SecretAgentCheckConfig(String id, int interval, Path checkExecutable, String... arguments) { - this.id = id; - this.interval = interval; - this.checkExecutable = checkExecutable; - this.arguments = arguments; - } - - public SecretAgentCheckConfig withRunAsUser(String user) { - this.user = user; - return this; - } - - public SecretAgentCheckConfig withTag(String tagKey, Object tagValue) { - tags.put(tagKey, tagValue); - return this; - } - - public SecretAgentCheckConfig withTags(Map<String, Object> tags) { - this.tags.clear(); - this.tags.putAll(tags); - return this; - } - - public void setTags(Map<String, Object> tags) { - this.tags.clear(); - this.tags.putAll(tags); - } - - public void writeTo(Path yamasAgentDirectory) throws IOException { - Files.createDirectories(yamasAgentDirectory); - Path scheduleFilePath = yamasAgentDirectory.resolve(id + ".yaml"); - Files.write(scheduleFilePath, render().getBytes()); - } - - public FileWriter getFileWriterTo(Path destinationPath) { - return new FileWriter(destinationPath, this::render); - } - - public String render() { - StringBuilder stringBuilder = new StringBuilder() - .append("- id: ").append(id).append("\n") - .append(" interval: ").append(interval).append("\n") - .append(" user: ").append(user).append("\n") - .append(" check: ").append(checkExecutable.toFile()).append("\n"); - - if (arguments.length > 0) { - stringBuilder.append(" args:\n"); - for (String arg : arguments) { - stringBuilder.append(" - ").append(arg).append("\n"); - } - } - - if (!tags.isEmpty()) { - stringBuilder.append(" tags:\n"); - tags.forEach((key, value) -> - stringBuilder.append(" ").append(key).append(": ").append(value).append("\n")); - } - - return stringBuilder.toString(); - } - - // TODO: Change role dimension to nodeType? - public static String nodeTypeToRole(NodeType nodeType) { - switch (nodeType) { - case tenant: return "tenants"; - case host: return "docker"; - case proxy: return "routing"; - case proxyhost: return "routinghost"; - case config: return "configserver"; - case confighost: return "configserverhost"; - case controller: return "controller"; - case controllerhost: return "controllerhost"; - default: throw new IllegalArgumentException("Unknown node type " + nodeType); - } - } -} diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/package-info.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/package-info.java deleted file mode 100644 index 56cb135e723..00000000000 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -@ExportPackage -package com.yahoo.vespa.hosted.node.admin.util; - -import com.yahoo.osgi.annotation.ExportPackage; |