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);
}
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;
}
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;
}
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);
}
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();
}
Aggregations