Search in sources :

Example 11 with JmxPrometheusExporterMetricsBuilder

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

the class MetricsIsolatedST method testKafkaMetricsSettings.

/**
 * 1. Update metrics form whatever it is to @metricsConfigYaml in spec.kafka.metricsConfig
 * 2. Check, whether the metrics ConfigMap is changed
 * 3. Updates ConfigMap linked as metrics on
 * 4. Check, whether the metrics ConfigMap is changed
 */
@ParallelTest
void testKafkaMetricsSettings() {
    String metricsConfigJson = "{\"lowercaseOutputName\":true}";
    String metricsConfigYaml = "lowercaseOutputName: true";
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true);
    ConfigMap externalMetricsCm = new ConfigMapBuilder().withData(Collections.singletonMap(Constants.METRICS_CONFIG_YAML_NAME, metricsConfigYaml)).withNewMetadata().withName("external-metrics-cm").withNamespace(SECOND_NAMESPACE).endMetadata().build();
    kubeClient().getClient().configMaps().inNamespace(SECOND_NAMESPACE).createOrReplace(externalMetricsCm);
    // spec.kafka.metrics -> spec.kafka.jmxExporterMetrics
    ConfigMapKeySelector cmks = new ConfigMapKeySelectorBuilder().withName("external-metrics-cm").withKey(Constants.METRICS_CONFIG_YAML_NAME).build();
    JmxPrometheusExporterMetrics jmxPrometheusExporterMetrics = new JmxPrometheusExporterMetricsBuilder().withNewValueFrom().withConfigMapKeyRef(cmks).endValueFrom().build();
    KafkaResource.replaceKafkaResourceInSpecificNamespace(SECOND_CLUSTER, k -> {
        k.getSpec().getKafka().setMetricsConfig(jmxPrometheusExporterMetrics);
    }, SECOND_NAMESPACE);
    PodUtils.verifyThatRunningPodsAreStable(SECOND_NAMESPACE, SECOND_CLUSTER);
    ConfigMap actualCm = kubeClient(SECOND_NAMESPACE).getConfigMap(KafkaResources.kafkaMetricsAndLogConfigMapName(SECOND_CLUSTER));
    assertThat(actualCm.getData().get(Constants.METRICS_CONFIG_JSON_NAME), is(metricsConfigJson));
    // update metrics
    ConfigMap externalMetricsUpdatedCm = new ConfigMapBuilder().withData(Collections.singletonMap(Constants.METRICS_CONFIG_YAML_NAME, metricsConfigYaml.replace("true", "false"))).withNewMetadata().withName("external-metrics-cm").withNamespace(SECOND_NAMESPACE).endMetadata().build();
    kubeClient().getClient().configMaps().inNamespace(SECOND_NAMESPACE).createOrReplace(externalMetricsUpdatedCm);
    PodUtils.verifyThatRunningPodsAreStable(SECOND_NAMESPACE, SECOND_CLUSTER);
    actualCm = kubeClient(SECOND_NAMESPACE).getConfigMap(KafkaResources.kafkaMetricsAndLogConfigMapName(SECOND_CLUSTER));
    assertThat(actualCm.getData().get(Constants.METRICS_CONFIG_JSON_NAME), is(metricsConfigJson.replace("true", "false")));
}
Also used : JmxPrometheusExporterMetrics(io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) JmxPrometheusExporterMetricsBuilder(io.strimzi.api.kafka.model.JmxPrometheusExporterMetricsBuilder) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Matchers.emptyString(org.hamcrest.Matchers.emptyString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigMapKeySelector(io.fabric8.kubernetes.api.model.ConfigMapKeySelector) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest)

Example 12 with JmxPrometheusExporterMetricsBuilder

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

the class KafkaConnectClusterTest method testMetricsParsingFromConfigMap.

@ParallelTest
public void testMetricsParsingFromConfigMap() {
    MetricsConfig metrics = new JmxPrometheusExporterMetricsBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName("my-metrics-configuration").withKey("config.yaml").build()).endValueFrom().build();
    KafkaConnect kafkaConnect = new KafkaConnectBuilder(this.resource).editSpec().withMetricsConfig(metrics).endSpec().build();
    KafkaConnectCluster kc = KafkaConnectCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaConnect, VERSIONS);
    assertThat(kc.isMetricsEnabled(), is(true));
    assertThat(kc.getMetricsConfigInCm(), is(metrics));
}
Also used : KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) JmxPrometheusExporterMetricsBuilder(io.strimzi.api.kafka.model.JmxPrometheusExporterMetricsBuilder) ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) MetricsConfig(io.strimzi.api.kafka.model.MetricsConfig) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 13 with JmxPrometheusExporterMetricsBuilder

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

the class KafkaMirrorMaker2ClusterTest method testMetricsParsingFromConfigMap.

@ParallelTest
public void testMetricsParsingFromConfigMap() {
    MetricsConfig metrics = new JmxPrometheusExporterMetricsBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName("my-metrics-configuration").withKey("config.yaml").build()).endValueFrom().build();
    KafkaMirrorMaker2 kafkaMirrorMaker2 = new KafkaMirrorMaker2Builder(this.resource).editSpec().withMetricsConfig(metrics).endSpec().build();
    KafkaMirrorMaker2Cluster kmm = KafkaMirrorMaker2Cluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaMirrorMaker2, VERSIONS);
    assertThat(kmm.isMetricsEnabled(), is(true));
    assertThat(kmm.getMetricsConfigInCm(), is(metrics));
}
Also used : KafkaMirrorMaker2Builder(io.strimzi.api.kafka.model.KafkaMirrorMaker2Builder) JmxPrometheusExporterMetricsBuilder(io.strimzi.api.kafka.model.JmxPrometheusExporterMetricsBuilder) ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) KafkaMirrorMaker2(io.strimzi.api.kafka.model.KafkaMirrorMaker2) MetricsConfig(io.strimzi.api.kafka.model.MetricsConfig) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 14 with JmxPrometheusExporterMetricsBuilder

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

the class KafkaTemplates method kafkaWithMetricsAndCruiseControlWithMetrics.

public static KafkaBuilder kafkaWithMetricsAndCruiseControlWithMetrics(String name, int kafkaReplicas, int zookeeperReplicas) {
    Kafka kafka = getKafkaFromYaml(Constants.PATH_TO_KAFKA_METRICS_CONFIG);
    ConfigMap kafkaMetricsCm = TestUtils.configMapFromYaml(Constants.PATH_TO_KAFKA_METRICS_CONFIG, "kafka-metrics");
    KubeClusterResource.kubeClient().getClient().configMaps().inNamespace(kubeClient().getNamespace()).createOrReplace(kafkaMetricsCm);
    ConfigMap zkMetricsCm = TestUtils.configMapFromYaml(Constants.PATH_TO_KAFKA_METRICS_CONFIG, "kafka-metrics");
    KubeClusterResource.kubeClient().getClient().configMaps().inNamespace(kubeClient().getNamespace()).createOrReplace(zkMetricsCm);
    ConfigMap ccCm = new ConfigMapBuilder().withApiVersion("v1").withNewMetadata().withName("cruise-control-metrics-test").withLabels(Collections.singletonMap("app", "strimzi")).endMetadata().withData(Collections.singletonMap("metrics-config.yml", "lowercaseOutputName: true\n" + "rules:\n" + "- pattern: kafka.cruisecontrol<name=(.+)><>(\\w+)\n" + "  name: kafka_cruisecontrol_$1_$2\n" + "  type: GAUGE")).build();
    KubeClusterResource.kubeClient().getClient().configMaps().inNamespace(kubeClient().getNamespace()).createOrReplace(ccCm);
    ConfigMapKeySelector cmks = new ConfigMapKeySelectorBuilder().withName("cruise-control-metrics-test").withKey("metrics-config.yml").build();
    JmxPrometheusExporterMetrics jmxPrometheusExporterMetrics = new JmxPrometheusExporterMetricsBuilder().withNewValueFrom().withConfigMapKeyRef(cmks).endValueFrom().build();
    return defaultKafka(kafka, name, kafkaReplicas, zookeeperReplicas).editSpec().withNewKafkaExporter().endKafkaExporter().withNewCruiseControl().withMetricsConfig(jmxPrometheusExporterMetrics).endCruiseControl().endSpec();
}
Also used : JmxPrometheusExporterMetrics(io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) JmxPrometheusExporterMetricsBuilder(io.strimzi.api.kafka.model.JmxPrometheusExporterMetricsBuilder) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) ConfigMapKeySelector(io.fabric8.kubernetes.api.model.ConfigMapKeySelector)

Example 15 with JmxPrometheusExporterMetricsBuilder

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

the class KafkaClusterTest method testMetricsParsingFromConfigMap.

@ParallelTest
public void testMetricsParsingFromConfigMap() {
    MetricsConfig metrics = new JmxPrometheusExporterMetricsBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName("my-metrics-configuration").withKey("config.yaml").build()).endValueFrom().build();
    Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().editKafka().withMetricsConfig(metrics).endKafka().endSpec().build();
    KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
    assertThat(kc.isMetricsEnabled(), is(true));
    assertThat(kc.getMetricsConfigInCm(), is(metrics));
}
Also used : JmxPrometheusExporterMetricsBuilder(io.strimzi.api.kafka.model.JmxPrometheusExporterMetricsBuilder) ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) MetricsConfig(io.strimzi.api.kafka.model.MetricsConfig) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

ConfigMapKeySelectorBuilder (io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder)18 JmxPrometheusExporterMetricsBuilder (io.strimzi.api.kafka.model.JmxPrometheusExporterMetricsBuilder)18 MetricsConfig (io.strimzi.api.kafka.model.MetricsConfig)12 ParallelTest (io.strimzi.test.annotations.ParallelTest)12 Kafka (io.strimzi.api.kafka.model.Kafka)8 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)6 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)6 JmxPrometheusExporterMetrics (io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ConfigMapKeySelector (io.fabric8.kubernetes.api.model.ConfigMapKeySelector)4 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)4 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)2 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)2 CruiseControlSpec (io.strimzi.api.kafka.model.CruiseControlSpec)2 CruiseControlSpecBuilder (io.strimzi.api.kafka.model.CruiseControlSpecBuilder)2 KafkaConnect (io.strimzi.api.kafka.model.KafkaConnect)2 KafkaConnectBuilder (io.strimzi.api.kafka.model.KafkaConnectBuilder)2 KafkaMirrorMaker (io.strimzi.api.kafka.model.KafkaMirrorMaker)2 KafkaMirrorMaker2 (io.strimzi.api.kafka.model.KafkaMirrorMaker2)2 KafkaMirrorMaker2Builder (io.strimzi.api.kafka.model.KafkaMirrorMaker2Builder)2