-
Notifications
You must be signed in to change notification settings - Fork 447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Low friction cleanups (suggested by IntelliJ) #361
base: master
Are you sure you want to change the base?
Changes from 14 commits
9a142e5
7a44bf2
dab0a20
10f8d3e
f9c41b9
60621c5
56656cd
7f92b6e
522ee83
faad4fd
7113e3f
a26d410
ce9d5ba
b46f575
53f532f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,7 @@ | |
*/ | ||
public class XinfraMonitorConstants { | ||
|
||
public XinfraMonitorConstants() { | ||
samba2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
} | ||
private XinfraMonitorConstants() {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. utility class |
||
|
||
public static final String TAGS_NAME = "name"; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
import com.linkedin.xinfra.monitor.services.configs.ProduceServiceConfig; | ||
import com.linkedin.xinfra.monitor.services.configs.TopicManagementServiceConfig; | ||
import com.linkedin.xinfra.monitor.services.metrics.ClusterTopicManipulationMetrics; | ||
|
||
import java.time.Duration; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
|
@@ -39,6 +41,7 @@ | |
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static com.linkedin.xinfra.monitor.common.Utils.delay; | ||
import static com.linkedin.xinfra.monitor.common.Utils.prettyPrint; | ||
|
||
/* | ||
|
@@ -94,14 +97,9 @@ public void start() throws Exception { | |
_topicManagementService.start(); | ||
CompletableFuture<Void> topicPartitionResult = _topicManagementService.topicPartitionResult(); | ||
|
||
try { | ||
/* Delay 2 second to reduce the chance that produce and consumer thread has race condition | ||
with TopicManagementService and MultiClusterTopicManagementService */ | ||
long threadSleepMs = TimeUnit.SECONDS.toMillis(2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to concisely use the |
||
Thread.sleep(threadSleepMs); | ||
} catch (InterruptedException e) { | ||
throw new Exception("Interrupted while sleeping the thread", e); | ||
} | ||
delay(Duration.ofSeconds(2)); | ||
CompletableFuture<Void> topicPartitionFuture = topicPartitionResult.thenRun(() -> { | ||
for (Service service : _allServices) { | ||
if (!service.isRunning()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,8 +55,6 @@ | |
*/ | ||
public class Utils { | ||
private static final Logger LOG = LoggerFactory.getLogger(Utils.class); | ||
public static final int ZK_CONNECTION_TIMEOUT_MS = 30_000; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused |
||
public static final int ZK_SESSION_TIMEOUT_MS = 30_000; | ||
private static final long LIST_PARTITION_REASSIGNMENTS_TIMEOUT_MS = 60000L; | ||
private static final int LIST_PARTITION_REASSIGNMENTS_MAX_ATTEMPTS = 3; | ||
private static final String LIST_PARTITION_REASSIGNMENTS_TIMEOUT_MS_CONFIG = "list.partition.reassignment.timeout.ms"; | ||
|
@@ -117,9 +115,7 @@ public static List<Integer> replicaIdentifiers(Set<BrokerMetadata> brokers) { | |
Collections.shuffle(brokerMetadataList); | ||
|
||
// Get broker ids for replica list | ||
List<Integer> replicaList = brokerMetadataList.stream().map(m -> m.id()).collect(Collectors.toList()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inline |
||
|
||
return replicaList; | ||
return brokerMetadataList.stream().map(m -> m.id()).collect(Collectors.toList()); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ public void commitAsync(OffsetCommitCallback callback) { | |
|
||
@Override | ||
public OffsetAndMetadata committed(TopicPartition tp) { | ||
return _consumer.committed(tp); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deprecated method |
||
return _consumer.committed(Collections.singleton(tp)).get(tp); | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,6 @@ public class ClusterTopicManipulationService implements Service { | |
|
||
private final ClusterTopicManipulationMetrics _clusterTopicManipulationMetrics; | ||
private final TopicFactory _topicFactory; | ||
private final String _zkConnect; | ||
|
||
public ClusterTopicManipulationService(String name, AdminClient adminClient, Map<String, Object> props) | ||
throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, | ||
|
@@ -96,7 +95,6 @@ public ClusterTopicManipulationService(String name, AdminClient adminClient, Map | |
TopicManagementServiceConfig.TOPIC_FACTORY_PROPS_CONFIG) : new HashMap(); | ||
|
||
_clusterTopicManipulationMetrics = new ClusterTopicManipulationMetrics(metrics, tags); | ||
_zkConnect = config.getString(TopicManagementServiceConfig.ZOOKEEPER_CONNECT_CONFIG); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused |
||
_topicFactory = | ||
(TopicFactory) Class.forName(topicFactoryClassName).getConstructor(Map.class).newInstance(topicFactoryConfig); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,10 +29,8 @@ | |
import org.apache.avro.generic.GenericRecord; | ||
import org.apache.kafka.clients.admin.AdminClient; | ||
import org.apache.kafka.clients.admin.TopicDescription; | ||
import org.apache.kafka.clients.consumer.OffsetAndMetadata; | ||
import org.apache.kafka.clients.consumer.OffsetCommitCallback; | ||
import org.apache.kafka.common.MetricName; | ||
import org.apache.kafka.common.TopicPartition; | ||
import org.apache.kafka.common.metrics.JmxReporter; | ||
import org.apache.kafka.common.metrics.MetricConfig; | ||
import org.apache.kafka.common.metrics.Metrics; | ||
|
@@ -117,9 +115,9 @@ public ConsumeService(String name, | |
topicPartitionFuture.get(); | ||
} | ||
|
||
private void consume() throws Exception { | ||
private void consume() { | ||
/* Delay 1 second to reduce the chance that consumer creates topic before TopicManagementService */ | ||
Thread.sleep(1000); | ||
Utils.delay(Duration.ofSeconds(1)); | ||
|
||
Map<Integer, Long> nextIndexes = new HashMap<>(); | ||
|
||
|
@@ -132,7 +130,7 @@ record = _baseConsumer.receive(); | |
LOG.warn(_name + "/ConsumeService failed to receive record", e); | ||
/* Avoid busy while loop */ | ||
//noinspection BusyWait | ||
Thread.sleep(CONSUME_THREAD_SLEEP_MS); | ||
Utils.delay(Duration.ofMillis(CONSUME_THREAD_SLEEP_MS)); | ||
continue; | ||
} | ||
|
||
|
@@ -152,16 +150,13 @@ record = _baseConsumer.receive(); | |
int partition = record.partition(); | ||
/* Commit availability and commit latency service */ | ||
/* Call commitAsync, wait for a NON-NULL return value (see https://issues.apache.org/jira/browse/KAFKA-6183) */ | ||
OffsetCommitCallback commitCallback = new OffsetCommitCallback() { | ||
@Override | ||
public void onComplete(Map<TopicPartition, OffsetAndMetadata> topicPartitionOffsetAndMetadataMap, Exception kafkaException) { | ||
if (kafkaException != null) { | ||
LOG.error("Exception while trying to perform an asynchronous commit.", kafkaException); | ||
_commitAvailabilityMetrics._failedCommitOffsets.record(); | ||
} else { | ||
_commitAvailabilityMetrics._offsetsCommitted.record(); | ||
_commitLatencyMetrics.recordCommitComplete(); | ||
} | ||
OffsetCommitCallback commitCallback = (topicPartitionOffsetAndMetadataMap, kafkaException) -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using lambdas instead of anonymous class |
||
if (kafkaException != null) { | ||
LOG.error("Exception while trying to perform an asynchronous commit.", kafkaException); | ||
_commitAvailabilityMetrics._failedCommitOffsets.record(); | ||
} else { | ||
_commitAvailabilityMetrics._offsetsCommitted.record(); | ||
_commitLatencyMetrics.recordCommitComplete(); | ||
} | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,6 @@ private void reportMetrics() { | |
builder.append("\n"); | ||
} | ||
} | ||
LOG.info("{}\n{}", LOG_DIVIDER, builder.toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. obsolete call |
||
LOG.info("{}\n{}", LOG_DIVIDER, builder); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,9 +74,7 @@ private Properties prepareConfigs(Map<String, Object> props) { | |
|
||
Map<String, String> customProps = (Map<String, String>) props.get(CommonServiceConfig.CONSUMER_PROPS_CONFIG); | ||
if (customProps != null) { | ||
for (Map.Entry<String, String> entry : customProps.entrySet()) { | ||
consumerProps.put(entry.getKey(), entry.getValue()); | ||
} | ||
consumerProps.putAll(customProps); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. never would have spotted this myself - putAll is a convenient shortcut + also more performant (I know, not relevant here) |
||
} | ||
|
||
return consumerProps; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,8 +52,8 @@ public SignalFxMetricsReporterService(Map<String, Object> props, String name) th | |
|
||
_executor = Executors.newSingleThreadScheduledExecutor(); | ||
_metricRegistry = new MetricRegistry(); | ||
_metricMap = new HashMap<String, SettableDoubleGauge>(); | ||
_dimensionsMap = new HashMap<String, String>(); | ||
_metricMap = new HashMap<>(); | ||
_dimensionsMap = new HashMap<>(); | ||
Comment on lines
+55
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was redundant |
||
if (props.containsKey(SignalFxMetricsReporterServiceConfig.SIGNALFX_METRIC_DIMENSION)) { | ||
_dimensionsMap = (Map<String, String>) props.get(SignalFxMetricsReporterServiceConfig.SIGNALFX_METRIC_DIMENSION); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
import java.util.Map; | ||
import org.apache.kafka.common.MetricName; | ||
import org.apache.kafka.common.metrics.Measurable; | ||
import org.apache.kafka.common.metrics.MetricConfig; | ||
import org.apache.kafka.common.metrics.Metrics; | ||
import org.apache.kafka.common.metrics.Sensor; | ||
import org.apache.kafka.common.metrics.stats.Avg; | ||
|
@@ -59,27 +58,24 @@ public OffsetCommitServiceMetrics(final Metrics metrics, final Map<String, Strin | |
"The total count of group coordinator unsuccessfully receiving consumer offset commit requests.", tags), | ||
new CumulativeSum()); | ||
|
||
Measurable measurable = new Measurable() { | ||
@Override | ||
public double measure(MetricConfig config, long now) { | ||
double offsetCommitSuccessRate = (double) metrics.metrics() | ||
.get(metrics.metricName(SUCCESS_RATE_METRIC, METRIC_GROUP_NAME, tags)) | ||
.metricValue(); | ||
double offsetCommitFailureRate = (double) metrics.metrics() | ||
.get(metrics.metricName(FAILURE_RATE_METRIC, METRIC_GROUP_NAME, tags)) | ||
.metricValue(); | ||
|
||
if (new Double(offsetCommitSuccessRate).isNaN()) { | ||
offsetCommitSuccessRate = 0; | ||
} | ||
|
||
if (new Double(offsetCommitFailureRate).isNaN()) { | ||
offsetCommitFailureRate = 0; | ||
} | ||
|
||
return offsetCommitSuccessRate + offsetCommitFailureRate > 0 ? offsetCommitSuccessRate / ( | ||
offsetCommitSuccessRate + offsetCommitFailureRate) : 0; | ||
Measurable measurable = (config, now) -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using lambda |
||
double offsetCommitSuccessRate = (double) metrics.metrics() | ||
.get(metrics.metricName(SUCCESS_RATE_METRIC, METRIC_GROUP_NAME, tags)) | ||
.metricValue(); | ||
double offsetCommitFailureRate = (double) metrics.metrics() | ||
.get(metrics.metricName(FAILURE_RATE_METRIC, METRIC_GROUP_NAME, tags)) | ||
.metricValue(); | ||
|
||
if (new Double(offsetCommitSuccessRate).isNaN()) { | ||
offsetCommitSuccessRate = 0; | ||
} | ||
|
||
if (new Double(offsetCommitFailureRate).isNaN()) { | ||
offsetCommitFailureRate = 0; | ||
} | ||
|
||
return offsetCommitSuccessRate + offsetCommitFailureRate > 0 ? offsetCommitSuccessRate / ( | ||
offsetCommitSuccessRate + offsetCommitFailureRate) : 0; | ||
}; | ||
|
||
metrics.addMetric(new MetricName("offset-commit-availability-avg", METRIC_GROUP_NAME, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was never called