aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/admin/otel/OpenTelemetryCollector.java
blob: 03b96b12c037ac4d187462c42a05dbf6d76ed7a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.admin.otel;

import com.yahoo.cloud.config.OpenTelemetryConfig;
import com.yahoo.config.model.ApplicationConfigProducerRoot;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.model.producer.TreeConfigProducer;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.Zone;
import com.yahoo.vespa.model.AbstractService;
import com.yahoo.vespa.model.PortAllocBridge;

import com.yahoo.cloud.config.ModelConfig;
import com.yahoo.config.model.producer.AnyConfigProducer;

import java.util.Optional;

public class OpenTelemetryCollector extends AbstractService implements OpenTelemetryConfig.Producer {

    private final Zone zone;
    private final ApplicationId applicationId;

    public OpenTelemetryCollector(TreeConfigProducer<?> parent) {
        super(parent, "otelcol");
        this.zone = null;
        this.applicationId = null;
        setProp("clustertype", "admin");
        setProp("clustername", "admin");
    }

    public OpenTelemetryCollector(TreeConfigProducer<?> parent, DeployState deployState) {
        super(parent, "otelcol");
        this.zone = deployState.zone();
        this.applicationId = deployState.getProperties().applicationId();
        setProp("clustertype", "admin");
        setProp("clustername", "admin");
    }

    /**
     * @return the startup command for the otelcol wrapper
     */
    @Override
    public Optional<String> getStartupCommand() {
        return Optional.of("exec $ROOT/bin/vespa-otelcol-start -c " + getConfigId());
    }

    @Override
    public void allocatePorts(int start, PortAllocBridge from) {}

    @Override
    public int getPortCount() {
        return 0;
    }

    @Override
    public void getConfig(OpenTelemetryConfig.Builder builder) {
        var generator = new OpenTelemetryConfigGenerator(zone, applicationId);
        AnyConfigProducer pp = this;
        AnyConfigProducer p = pp.getParent();
        while (p != null && p != pp) {
            if (pp instanceof ApplicationConfigProducerRoot root) {
                generator.addStatePorts(root.getStatePorts());
                break;
            }
            pp = p;
            p = pp.getParent();
        }
        builder.yaml(generator.generate());
        builder.refPaths(generator.referencedPaths());
    }
}