use of com.linkedin.kafka.cruisecontrol.metricsreporter.exception.CruiseControlMetricsReporterException in project cruise-control by linkedin.
the class CruiseControlMetricsReporter method configure.
@Override
public void configure(Map<String, ?> configs) {
Properties producerProps = CruiseControlMetricsReporterConfig.parseProducerConfigs(configs);
// Add BootstrapServers if not set
if (!producerProps.containsKey(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG)) {
String bootstrapServers = getBootstrapServers(configs);
producerProps.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
LOG.info("Using default value of {} for {}", bootstrapServers, CruiseControlMetricsReporterConfig.config(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG));
}
// Add SecurityProtocol if not set
if (!producerProps.containsKey(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG)) {
String securityProtocol = "PLAINTEXT";
producerProps.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, securityProtocol);
LOG.info("Using default value of {} for {}", securityProtocol, CruiseControlMetricsReporterConfig.config(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG));
}
CruiseControlMetricsReporterConfig reporterConfig = new CruiseControlMetricsReporterConfig(configs, false);
setIfAbsent(producerProps, ProducerConfig.CLIENT_ID_CONFIG, reporterConfig.getString(CruiseControlMetricsReporterConfig.config(CommonClientConfigs.CLIENT_ID_CONFIG)));
setIfAbsent(producerProps, ProducerConfig.LINGER_MS_CONFIG, reporterConfig.getLong(CruiseControlMetricsReporterConfig.CRUISE_CONTROL_METRICS_REPORTER_LINGER_MS_CONFIG).toString());
setIfAbsent(producerProps, ProducerConfig.BATCH_SIZE_CONFIG, reporterConfig.getInt(CruiseControlMetricsReporterConfig.CRUISE_CONTROL_METRICS_REPORTER_BATCH_SIZE_CONFIG).toString());
setIfAbsent(producerProps, ProducerConfig.RETRIES_CONFIG, "5");
setIfAbsent(producerProps, ProducerConfig.COMPRESSION_TYPE_CONFIG, "gzip");
setIfAbsent(producerProps, ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
setIfAbsent(producerProps, ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, MetricSerde.class.getName());
setIfAbsent(producerProps, ProducerConfig.ACKS_CONFIG, "all");
_metricsReporterCreateRetries = reporterConfig.getInt(CruiseControlMetricsReporterConfig.CRUISE_CONTROL_METRICS_REPORTER_CREATE_RETRIES_CONFIG);
createCruiseControlMetricsProducer(producerProps);
if (_producer == null) {
this.close();
}
_brokerId = Integer.parseInt((String) configs.get(KafkaConfig.BrokerIdProp()));
_cruiseControlMetricsTopic = reporterConfig.getString(CruiseControlMetricsReporterConfig.CRUISE_CONTROL_METRICS_TOPIC_CONFIG);
_reportingIntervalMs = reporterConfig.getLong(CruiseControlMetricsReporterConfig.CRUISE_CONTROL_METRICS_REPORTER_INTERVAL_MS_CONFIG);
_kubernetesMode = reporterConfig.getBoolean(CruiseControlMetricsReporterConfig.CRUISE_CONTROL_METRICS_REPORTER_KUBERNETES_MODE_CONFIG);
if (reporterConfig.getBoolean(CruiseControlMetricsReporterConfig.CRUISE_CONTROL_METRICS_TOPIC_AUTO_CREATE_CONFIG)) {
try {
_metricsTopic = createMetricsTopicFromReporterConfig(reporterConfig);
Properties adminClientConfigs = CruiseControlMetricsUtils.addSslConfigs(producerProps, reporterConfig);
_adminClient = CruiseControlMetricsUtils.createAdminClient(adminClientConfigs);
_metricsTopicAutoCreateTimeoutMs = reporterConfig.getLong(CruiseControlMetricsReporterConfig.CRUISE_CONTROL_METRICS_TOPIC_AUTO_CREATE_TIMEOUT_MS_CONFIG);
_metricsTopicAutoCreateRetries = reporterConfig.getInt(CruiseControlMetricsReporterConfig.CRUISE_CONTROL_METRICS_TOPIC_AUTO_CREATE_RETRIES_CONFIG);
} catch (CruiseControlMetricsReporterException e) {
LOG.warn("Cruise Control metrics topic auto creation was disabled", e);
}
}
}
use of com.linkedin.kafka.cruisecontrol.metricsreporter.exception.CruiseControlMetricsReporterException in project cruise-control by linkedin.
the class CruiseControlMetricsReporter method createMetricsTopicFromReporterConfig.
protected NewTopic createMetricsTopicFromReporterConfig(CruiseControlMetricsReporterConfig reporterConfig) throws CruiseControlMetricsReporterException {
String cruiseControlMetricsTopic = reporterConfig.getString(CruiseControlMetricsReporterConfig.CRUISE_CONTROL_METRICS_TOPIC_CONFIG);
Integer cruiseControlMetricsTopicNumPartition = reporterConfig.getInt(CruiseControlMetricsReporterConfig.CRUISE_CONTROL_METRICS_TOPIC_NUM_PARTITIONS_CONFIG);
Short cruiseControlMetricsTopicReplicaFactor = reporterConfig.getShort(CruiseControlMetricsReporterConfig.CRUISE_CONTROL_METRICS_TOPIC_REPLICATION_FACTOR_CONFIG);
Short cruiseControlMetricsTopicMinInsyncReplicas = reporterConfig.getShort(CruiseControlMetricsReporterConfig.CRUISE_CONTROL_METRICS_TOPIC_MIN_INSYNC_REPLICAS_CONFIG);
if (cruiseControlMetricsTopicReplicaFactor <= 0 || cruiseControlMetricsTopicNumPartition <= 0) {
throw new CruiseControlMetricsReporterException("The topic configuration must explicitly set the replication factor and the num partitions");
}
NewTopic newTopic = new NewTopic(cruiseControlMetricsTopic, cruiseControlMetricsTopicNumPartition, cruiseControlMetricsTopicReplicaFactor);
Map<String, String> config = new HashMap<>();
config.put(LogConfig.RetentionMsProp(), Long.toString(reporterConfig.getLong(CruiseControlMetricsReporterConfig.CRUISE_CONTROL_METRICS_TOPIC_RETENTION_MS_CONFIG)));
config.put(LogConfig.CleanupPolicyProp(), CRUISE_CONTROL_METRICS_TOPIC_CLEAN_UP_POLICY);
if (cruiseControlMetricsTopicMinInsyncReplicas > 0) {
// minISR to be met.
if (cruiseControlMetricsTopicReplicaFactor >= cruiseControlMetricsTopicMinInsyncReplicas) {
config.put(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG, String.valueOf(cruiseControlMetricsTopicMinInsyncReplicas));
} else {
throw new CruiseControlMetricsReporterException(String.format("The configured topic replication factor (%d) must be greater than or equal to the configured topic minimum insync replicas (%d)", cruiseControlMetricsTopicReplicaFactor, cruiseControlMetricsTopicMinInsyncReplicas));
}
// If the user does not set the metrics minISR we do not set that config and use the Kafka cluster's default.
}
newTopic.configs(config);
return newTopic;
}
Aggregations