k8s: pod logs and metrics reach the hive collector
This commit is contained in:
parent
f7f298ff4f
commit
ba0c41048e
1 changed files with 447 additions and 51 deletions
|
|
@ -92,14 +92,27 @@ let
|
|||
_: v: builtins.replaceStrings [ "%d" ] [ "/run/credentials/${name}.service" ] (toString v)
|
||||
) (removeAttrs units.${name}.environment [ "PATH" ]);
|
||||
|
||||
# Where a pod pushes telemetry: the name the hive collector answers to, on
|
||||
# the port it binds. A literal, so the render and the collector are not
|
||||
# compared with themselves.
|
||||
collectorEndpoint = "http://hive-collector.hive:4318";
|
||||
|
||||
# What the pod adds on top of the unit's own environment.
|
||||
added = {
|
||||
swarm-controller = {
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT = collectorEndpoint;
|
||||
RUNTIME_DIRECTORY = "/run/swarm-controller";
|
||||
STATE_DIRECTORY = "/var/lib/swarm-controller";
|
||||
};
|
||||
swarm-notify-router.SWARM_NOTIFY_ROUTER_HEALTH_ADDR = "0.0.0.0:8080";
|
||||
swarm-ci-metrics.STATE_DIRECTORY = "/var/lib/swarm-ci-metrics";
|
||||
swarm-notify-router = {
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT = collectorEndpoint;
|
||||
SWARM_NOTIFY_ROUTER_HEALTH_ADDR = "0.0.0.0:8080";
|
||||
};
|
||||
swarm-ci-metrics = {
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT = collectorEndpoint;
|
||||
SWARM_CI_METRICS_OTLP_ENDPOINT = collectorEndpoint;
|
||||
STATE_DIRECTORY = "/var/lib/swarm-ci-metrics";
|
||||
};
|
||||
};
|
||||
|
||||
# Host paths the credentials are loaded from: the host units' own
|
||||
|
|
@ -241,11 +254,19 @@ let
|
|||
&& lib.subtractLists (names withNode.systemd.services) (names allLocal.systemd.services) == [ ]
|
||||
&& lib.elem "k3s" added
|
||||
&& lib.all (n: lib.hasPrefix "k3s" n) added
|
||||
&& lib.all (
|
||||
n:
|
||||
withNode.systemd.services.${n}.serviceConfig.ExecStart or null
|
||||
== allLocal.systemd.services.${n}.serviceConfig.ExecStart or null
|
||||
) (lib.remove "firewall" (names allLocal.systemd.services))
|
||||
&&
|
||||
lib.all
|
||||
(
|
||||
n:
|
||||
withNode.systemd.services.${n}.serviceConfig.ExecStart or null
|
||||
== allLocal.systemd.services.${n}.serviceConfig.ExecStart or null
|
||||
)
|
||||
(
|
||||
lib.subtractLists [
|
||||
"firewall"
|
||||
"opentelemetry-collector"
|
||||
] (names allLocal.systemd.services)
|
||||
)
|
||||
&& withNode.system.build.k8sManifests.drvPath == allLocal.system.build.k8sManifests.drvPath;
|
||||
}
|
||||
{
|
||||
|
|
@ -305,6 +326,105 @@ let
|
|||
&& nodeNoBridge.services.hyperhive.deploy.k8s.hostServices == { }
|
||||
&& !(nodeNoBridge.services.k3s.manifests ? coredns-custom);
|
||||
}
|
||||
{
|
||||
# The units' own endpoints are the control: each differs from the
|
||||
# collector's, so the override replaces something. The host's units keep
|
||||
# theirs.
|
||||
name = "every pod pushes telemetry to the hive collector, and the host units keep their endpoints";
|
||||
ok =
|
||||
lib.all (
|
||||
name:
|
||||
(envOf name).OTEL_EXPORTER_OTLP_ENDPOINT == collectorEndpoint
|
||||
&& (units.${name}.environment.OTEL_EXPORTER_OTLP_ENDPOINT or null) != collectorEndpoint
|
||||
) (lib.attrNames units)
|
||||
&& units.swarm-ci-metrics.environment.SWARM_CI_METRICS_OTLP_ENDPOINT != collectorEndpoint
|
||||
&& (envOf "swarm-ci-metrics").SWARM_CI_METRICS_OTLP_ENDPOINT == collectorEndpoint
|
||||
&& !(envOf "swarm-notify-router" ? SWARM_CI_METRICS_OTLP_ENDPOINT)
|
||||
&&
|
||||
allLocal.systemd.services.swarm-controller.environment.OTEL_EXPORTER_OTLP_ENDPOINT
|
||||
== "https://${allLocal.services.hyperhive.swarm.otel.domain}/${allLocal.services.hyperhive.swarm.otel.producerName}";
|
||||
}
|
||||
{
|
||||
# Off, the collector's configuration holds nothing of the pod logs, and
|
||||
# on, taking that out leaves the configuration it has off. The host with
|
||||
# the node on is the control that the lookups find what is there.
|
||||
name = "the collector reads pod logs only where deploy.k8s.enable is set";
|
||||
ok =
|
||||
let
|
||||
mine = {
|
||||
receivers = [ "file_log/pods" ];
|
||||
processors = [ "transform/pod-service-name" ];
|
||||
};
|
||||
settings = c: c.services.opentelemetry-collector.settings;
|
||||
bare =
|
||||
s:
|
||||
s
|
||||
// {
|
||||
receivers = removeAttrs s.receivers mine.receivers;
|
||||
processors = removeAttrs s.processors mine.processors;
|
||||
service = s.service // {
|
||||
pipelines = removeAttrs s.service.pipelines [ "logs/pods" ];
|
||||
};
|
||||
};
|
||||
unit = c: c.systemd.services.opentelemetry-collector.serviceConfig;
|
||||
collectorAcls = c: lib.filter (lib.hasInfix "u:opentelemetry-collector:") c.systemd.tmpfiles.rules;
|
||||
in
|
||||
!((settings allLocal).receivers ? "file_log/pods")
|
||||
&& !((settings allLocal).service.pipelines ? "logs/pods")
|
||||
&& (settings withNode).receivers ? "file_log/pods"
|
||||
&& (settings withNode).service.pipelines ? "logs/pods"
|
||||
&& bare (settings withNode) == settings allLocal
|
||||
&& (unit allLocal).DynamicUser
|
||||
&& !(unit allLocal ? User)
|
||||
&& !(allLocal.users.users ? opentelemetry-collector)
|
||||
&& collectorAcls allLocal == [ ]
|
||||
&& !(unit withNode).DynamicUser
|
||||
&& (unit withNode).User == "opentelemetry-collector"
|
||||
&& withNode.users.users.opentelemetry-collector.isSystemUser;
|
||||
}
|
||||
{
|
||||
# The receiver reads the files kubelet's runtime writes, the parser reads
|
||||
# the CRI framing and then hive-log's level, and the service name is the
|
||||
# container's without `swarm-`. The ACL is on /var/log/pods alone, access
|
||||
# and default, for the collector's user.
|
||||
name = "the pod logs receiver parses CRI and the text level, names the service, and the ACL covers /var/log/pods only";
|
||||
ok =
|
||||
let
|
||||
s = withNode.services.opentelemetry-collector.settings;
|
||||
r = s.receivers."file_log/pods";
|
||||
ops = r.operators;
|
||||
op = t: lib.findFirst (o: o.type == t) null ops;
|
||||
statements = lib.concatMap (
|
||||
l: l.statements
|
||||
) s.processors."transform/pod-service-name".log_statements;
|
||||
acls = lib.filter (lib.hasInfix "u:opentelemetry-collector:") withNode.systemd.tmpfiles.rules;
|
||||
in
|
||||
r.include == [ "/var/log/pods/*/*/*.log" ]
|
||||
&& r.include_file_path
|
||||
&& r.storage == "file_storage"
|
||||
&& (lib.head ops).type == "container"
|
||||
&& lib.all (l: lib.hasInfix l (op "regex_parser").regex) [
|
||||
"WARN"
|
||||
"ERROR"
|
||||
"INFO"
|
||||
"DEBUG"
|
||||
"TRACE"
|
||||
]
|
||||
&& (op "severity_parser").parse_from == "attributes.level"
|
||||
&& (op "severity_parser").overwrite_text
|
||||
&& lib.elem ''set(attributes["service.name"], attributes["k8s.container.name"])'' statements
|
||||
&& lib.elem ''replace_pattern(attributes["service.name"], "^swarm-", "")'' statements
|
||||
&&
|
||||
s.service.pipelines."logs/pods" == {
|
||||
receivers = [ "file_log/pods" ];
|
||||
processors = [ "transform/pod-service-name" ];
|
||||
exporters = [ "otlphttp/swarm" ];
|
||||
}
|
||||
&& s.exporters ? "otlphttp/swarm"
|
||||
&& lib.elem "file_storage" s.service.extensions
|
||||
&&
|
||||
acls == [ "A+ /var/log/pods - - - - u:opentelemetry-collector:rX,d:u:opentelemetry-collector:rX" ];
|
||||
}
|
||||
];
|
||||
in
|
||||
runGroup "k8s" cases
|
||||
|
|
|
|||
Loading…
Reference in a new issue