Search in sources :

Example 1 with JmxPrometheusExporterMetrics

use of io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics in project strimzi by strimzi.

the class KafkaAssemblyOperatorTest method testUpdateZkClusterMetricsConfig.

@ParameterizedTest
@MethodSource("data")
public void testUpdateZkClusterMetricsConfig(Params params, VertxTestContext context) {
    setFields(params);
    Kafka kafkaAssembly = getKafkaAssembly("bar");
    JmxPrometheusExporterMetrics jmxMetricsConfig = io.strimzi.operator.cluster.TestUtils.getJmxPrometheusExporterMetrics("metrics-config.yml", differentMetricsCMName);
    kafkaAssembly.getSpec().getKafka().setMetricsConfig(jmxMetricsConfig);
    updateCluster(context, getKafkaAssembly("bar"), kafkaAssembly);
}
Also used : JmxPrometheusExporterMetrics(io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics) Kafka(io.strimzi.api.kafka.model.Kafka) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with JmxPrometheusExporterMetrics

use of io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics in project strimzi by strimzi.

the class AbstractModel method parseMetrics.

protected String parseMetrics(ConfigMap externalCm) {
    if (getMetricsConfigInCm() != null) {
        if (getMetricsConfigInCm() instanceof JmxPrometheusExporterMetrics) {
            if (externalCm == null) {
                LOGGER.warnCr(reconciliation, "ConfigMap {} does not exist. Metrics disabled.", ((JmxPrometheusExporterMetrics) getMetricsConfigInCm()).getValueFrom().getConfigMapKeyRef().getName());
                throw new InvalidResourceException("ConfigMap " + ((JmxPrometheusExporterMetrics) getMetricsConfigInCm()).getValueFrom().getConfigMapKeyRef().getName() + " does not exist.");
            } else {
                String data = externalCm.getData().get(((JmxPrometheusExporterMetrics) getMetricsConfigInCm()).getValueFrom().getConfigMapKeyRef().getKey());
                if (data == null) {
                    LOGGER.warnCr(reconciliation, "ConfigMap {} does not contain specified key {}. Metrics disabled.", ((JmxPrometheusExporterMetrics) getMetricsConfigInCm()).getValueFrom().getConfigMapKeyRef().getName(), ((JmxPrometheusExporterMetrics) getMetricsConfigInCm()).getValueFrom().getConfigMapKeyRef().getKey());
                    throw new InvalidResourceException("ConfigMap " + ((JmxPrometheusExporterMetrics) getMetricsConfigInCm()).getValueFrom().getConfigMapKeyRef().getName() + " does not contain specified key " + ((JmxPrometheusExporterMetrics) getMetricsConfigInCm()).getValueFrom().getConfigMapKeyRef().getKey() + ".");
                } else {
                    if (data.isEmpty()) {
                        return "{}";
                    }
                    try {
                        ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
                        Object yaml = yamlReader.readValue(data, Object.class);
                        ObjectMapper jsonWriter = new ObjectMapper();
                        return jsonWriter.writeValueAsString(yaml);
                    } catch (JsonProcessingException e) {
                        throw new InvalidResourceException("Parsing metrics configuration failed. ", e);
                    }
                }
            }
        } else {
            LOGGER.warnCr(reconciliation, "Unknown type of metrics {}.", getMetricsConfigInCm().getClass());
            throw new InvalidResourceException("Unknown type of metrics " + getMetricsConfigInCm().getClass() + ".");
        }
    }
    return null;
}
Also used : JmxPrometheusExporterMetrics(io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with JmxPrometheusExporterMetrics

use of io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics in project strimzi-kafka-operator by strimzi.

the class AbstractModel method parseMetrics.

protected String parseMetrics(ConfigMap externalCm) {
    if (getMetricsConfigInCm() != null) {
        if (getMetricsConfigInCm() instanceof JmxPrometheusExporterMetrics) {
            if (externalCm == null) {
                LOGGER.warnCr(reconciliation, "ConfigMap {} does not exist. Metrics disabled.", ((JmxPrometheusExporterMetrics) getMetricsConfigInCm()).getValueFrom().getConfigMapKeyRef().getName());
                throw new InvalidResourceException("ConfigMap " + ((JmxPrometheusExporterMetrics) getMetricsConfigInCm()).getValueFrom().getConfigMapKeyRef().getName() + " does not exist.");
            } else {
                String data = externalCm.getData().get(((JmxPrometheusExporterMetrics) getMetricsConfigInCm()).getValueFrom().getConfigMapKeyRef().getKey());
                if (data == null) {
                    LOGGER.warnCr(reconciliation, "ConfigMap {} does not contain specified key {}. Metrics disabled.", ((JmxPrometheusExporterMetrics) getMetricsConfigInCm()).getValueFrom().getConfigMapKeyRef().getName(), ((JmxPrometheusExporterMetrics) getMetricsConfigInCm()).getValueFrom().getConfigMapKeyRef().getKey());
                    throw new InvalidResourceException("ConfigMap " + ((JmxPrometheusExporterMetrics) getMetricsConfigInCm()).getValueFrom().getConfigMapKeyRef().getName() + " does not contain specified key " + ((JmxPrometheusExporterMetrics) getMetricsConfigInCm()).getValueFrom().getConfigMapKeyRef().getKey() + ".");
                } else {
                    if (data.isEmpty()) {
                        return "{}";
                    }
                    try {
                        ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
                        Object yaml = yamlReader.readValue(data, Object.class);
                        ObjectMapper jsonWriter = new ObjectMapper();
                        return jsonWriter.writeValueAsString(yaml);
                    } catch (JsonProcessingException e) {
                        throw new InvalidResourceException("Parsing metrics configuration failed. ", e);
                    }
                }
            }
        } else {
            LOGGER.warnCr(reconciliation, "Unknown type of metrics {}.", getMetricsConfigInCm().getClass());
            throw new InvalidResourceException("Unknown type of metrics " + getMetricsConfigInCm().getClass() + ".");
        }
    }
    return null;
}
Also used : JmxPrometheusExporterMetrics(io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with JmxPrometheusExporterMetrics

use of io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics in project strimzi-kafka-operator by strimzi.

the class KafkaAssemblyOperatorTest method testUpdateZkClusterMetricsConfig.

@ParameterizedTest
@MethodSource("data")
public void testUpdateZkClusterMetricsConfig(Params params, VertxTestContext context) {
    setFields(params);
    Kafka kafkaAssembly = getKafkaAssembly("bar");
    JmxPrometheusExporterMetrics jmxMetricsConfig = io.strimzi.operator.cluster.TestUtils.getJmxPrometheusExporterMetrics("metrics-config.yml", differentMetricsCMName);
    kafkaAssembly.getSpec().getKafka().setMetricsConfig(jmxMetricsConfig);
    updateCluster(context, getKafkaAssembly("bar"), kafkaAssembly);
}
Also used : JmxPrometheusExporterMetrics(io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics) Kafka(io.strimzi.api.kafka.model.Kafka) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with JmxPrometheusExporterMetrics

use of io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics in project strimzi-kafka-operator by strimzi.

the class KafkaAssemblyOperatorTest method getKafkaAssembly.

private Kafka getKafkaAssembly(String clusterName) {
    String clusterNamespace = "test";
    int replicas = 3;
    String image = "bar";
    int healthDelay = 120;
    int healthTimeout = 30;
    KafkaExporterSpec exporter = metrics ? new KafkaExporterSpec() : null;
    String metricsCMName = "metrics-cm";
    JmxPrometheusExporterMetrics jmxMetricsConfig = metrics ? null : io.strimzi.operator.cluster.TestUtils.getJmxPrometheusExporterMetrics("metrics-config.yml", metricsCMName);
    Kafka resource = ResourceUtils.createKafka(clusterNamespace, clusterName, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, kafkaConfig, zooConfig, kafkaStorage, zkStorage, LOG_KAFKA_CONFIG, LOG_ZOOKEEPER_CONFIG, exporter, null);
    return new KafkaBuilder(resource).editSpec().editKafka().withListeners(kafkaListeners).endKafka().withEntityOperator(eoConfig).endSpec().build();
}
Also used : JmxPrometheusExporterMetrics(io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics) KafkaExporterSpec(io.strimzi.api.kafka.model.KafkaExporterSpec) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Checkpoint(io.vertx.junit5.Checkpoint)

Aggregations

JmxPrometheusExporterMetrics (io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)6 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)6 ConfigMapKeySelectorBuilder (io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder)6 JmxPrometheusExporterMetricsBuilder (io.strimzi.api.kafka.model.JmxPrometheusExporterMetricsBuilder)6 Kafka (io.strimzi.api.kafka.model.Kafka)6 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)4 ConfigMapKeySelector (io.fabric8.kubernetes.api.model.ConfigMapKeySelector)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)2 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)2 KafkaExporterSpec (io.strimzi.api.kafka.model.KafkaExporterSpec)2 IsolatedTest (io.strimzi.systemtest.annotations.IsolatedTest)2 ParallelTest (io.strimzi.systemtest.annotations.ParallelTest)2 MetricsCollector (io.strimzi.systemtest.metrics.MetricsCollector)2 Checkpoint (io.vertx.junit5.Checkpoint)2 HashMap (java.util.HashMap)2 Matchers.emptyString (org.hamcrest.Matchers.emptyString)2