aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/application/validation/CloudWatchValidator.java
blob: 67be9d7bad82416cc1e05f37fadf5e800b7e7d0a (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.application.validation;

import com.yahoo.config.model.ConfigModelContext;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.vespa.model.VespaModel;
import com.yahoo.vespa.model.admin.monitoring.MetricsConsumer;

import java.util.List;

import static java.util.stream.Collectors.toList;

/**
 * @author gjoranv
 */
public class CloudWatchValidator extends Validator {

    @Override
    public void validate(VespaModel model, DeployState deployState) {
        if (!deployState.isHosted()) return;
        if (deployState.zone().system().isPublic()) return;
        if (model.getAdmin().getApplicationType() != ConfigModelContext.ApplicationType.DEFAULT) return;

        var offendingConsumers = model.getAdmin().getUserMetrics().getConsumers().values().stream()
                .filter(consumer -> !consumer.cloudWatches().isEmpty())
                .collect(toList());

        if (! offendingConsumers.isEmpty()) {
            throw new IllegalArgumentException("CloudWatch cannot be set up for non-public hosted Vespa and must " +
                                                       "be removed for consumers: " + consumerIds(offendingConsumers));
        }
    }

    private List<String> consumerIds(List<MetricsConsumer> offendingConsumers) {
        return offendingConsumers.stream().map(MetricsConsumer::id).collect(toList());
    }

}