-
Notifications
You must be signed in to change notification settings - Fork 139
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
fixes #71: Feature: Health check and metrics #464
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
parallel-consumer-core/src/main/java/io/confluent/parallelconsumer/Offsets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.confluent.parallelconsumer; | ||
|
||
/*- | ||
* Copyright (C) 2020-2022 Confluent, Inc. | ||
*/ | ||
|
||
import lombok.Getter; | ||
import lombok.ToString; | ||
import lombok.Value; | ||
import lombok.experimental.Delegate; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.SortedSet; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* A range of {@link Offset}s. | ||
*/ | ||
@ToString | ||
public class Offsets { | ||
|
||
@Getter | ||
@Delegate | ||
private final List<Long> rawOffsets; | ||
|
||
public Offsets(List<Long> records) { | ||
this.rawOffsets = records; | ||
} | ||
|
||
public static Offsets fromRecords(List<RecordContext<?, ?>> records) { | ||
return fromLongs(records.stream() | ||
.map(RecordContext::offset) | ||
.collect(Collectors.toList())); | ||
} | ||
|
||
// due to type erasure, can't use method overloading | ||
public static Offsets fromLongs(List<Long> rawOffsetsIn) { | ||
return new Offsets(rawOffsetsIn); | ||
} | ||
|
||
public static Offsets fromArray(long... rawOffsetsIn) { | ||
return new Offsets(Arrays.stream(rawOffsetsIn).boxed().collect(Collectors.toList())); | ||
} | ||
|
||
public static Offsets from(SortedSet<Long> incompleteOffsetsBelowHighestSucceeded) { | ||
return new Offsets(new ArrayList<>(incompleteOffsetsBelowHighestSucceeded)); | ||
} | ||
|
||
/** | ||
* Class value for a Kafka offset, to avoid being Longly typed. | ||
*/ | ||
@Value | ||
public static class Offset { | ||
long value; | ||
|
||
public static Offset of(Long offset) { | ||
return new Offset(offset); | ||
} | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
parallel-consumer-core/src/main/java/io/confluent/parallelconsumer/PCMetrics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package io.confluent.parallelconsumer; | ||
|
||
/*- | ||
* Copyright (C) 2020-2022 Confluent, Inc. | ||
*/ | ||
|
||
import io.confluent.parallelconsumer.internal.AbstractParallelEoSStreamProcessor; | ||
import io.confluent.parallelconsumer.internal.State; | ||
import io.confluent.parallelconsumer.offsets.OffsetEncoding; | ||
import io.confluent.parallelconsumer.state.ShardKey; | ||
import lombok.Builder; | ||
import lombok.Value; | ||
import lombok.experimental.SuperBuilder; | ||
import org.apache.kafka.common.TopicPartition; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Metrics model for Parallel Consumer | ||
* | ||
* @author Antony Stubbs | ||
*/ | ||
@Value | ||
@SuperBuilder(toBuilder = true) | ||
public class PCMetrics { | ||
|
||
long dynamicLoadFactor; | ||
|
||
Map<TopicPartition, PCPartitionMetrics> partitionMetrics; | ||
|
||
Map<ShardKey, ShardMetrics> shardMetrics; | ||
|
||
PollerMetrics pollerMetrics; | ||
|
||
/** | ||
* The number of partitions assigned to this consumer | ||
*/ | ||
public long getNumberOfPartitions() { | ||
return partitionMetrics.size(); | ||
} | ||
|
||
/** | ||
* The number of shards (queues) currently managed - depends on ordering and data key set | ||
*/ | ||
public long getNumberOfShards() { | ||
return shardMetrics.size(); | ||
} | ||
|
||
public long getTotalNumberOfIncompletes() { | ||
return partitionMetrics.values().stream() | ||
.mapToLong(PCPartitionMetrics::getNumberOfIncompletes) | ||
.sum(); | ||
} | ||
|
||
@Value | ||
@SuperBuilder(toBuilder = true) | ||
public static class PCPartitionMetrics { | ||
TopicPartition topicPartition; | ||
long lastCommittedOffset; | ||
long numberOfIncompletes; | ||
long highestCompletedOffset; | ||
long highestSeenOffset; | ||
long highestSequentialSucceededOffset; | ||
long epoch; | ||
CompressionStats compressionStats; | ||
|
||
/** | ||
* @see AbstractParallelEoSStreamProcessor#calculateMetricsWithIncompletes() | ||
*/ | ||
@Builder.Default | ||
Optional<IncompleteMetrics> incompleteMetrics = Optional.empty(); | ||
|
||
public long getTraditionalConsumerLag() { | ||
return highestSeenOffset - highestSequentialSucceededOffset; | ||
} | ||
|
||
@Value | ||
public static class IncompleteMetrics { | ||
Offsets incompleteOffsets; | ||
} | ||
|
||
@Value | ||
@SuperBuilder(toBuilder = true) | ||
public static class CompressionStats { | ||
long offsetsEncodedPerBit; | ||
long offsetsEncodedPerByte; | ||
long bytesUsedForEncoding; | ||
double fractionOfEncodingSpaceUsed; | ||
OffsetEncoding bestEncoding; | ||
} | ||
} | ||
|
||
@Value | ||
@SuperBuilder(toBuilder = true) | ||
public static class ShardMetrics { | ||
ShardKey shardKey; | ||
/** | ||
* Number of records queued for processing in this shard | ||
*/ | ||
long shardSize; | ||
long averageUserProcessingTime; | ||
long averageTimeSpentInQueue; | ||
} | ||
|
||
/** | ||
* Metrics for the {@link io.confluent.parallelconsumer.internal.BrokerPollSystem} sub-system. | ||
*/ | ||
@Value | ||
@SuperBuilder(toBuilder = true) | ||
public static class PollerMetrics { | ||
State state; | ||
boolean paused; | ||
Map<TopicPartition, Boolean> pausedPartitions; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we invert this? Move the construction into the metrics class, instead of the state class? (pass the metrics class the state)