sv2000 commented on a change in pull request #2795: GOBBLIN-945: Refactor Kafka extractor statistics tracking to allow co… URL: https://github.com/apache/incubator-gobblin/pull/2795#discussion_r342929192
########## File path: gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/KafkaExtractorStatsTracker.java ########## @@ -0,0 +1,320 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.gobblin.source.extractor.extract.kafka; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; + +import lombok.Data; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; + +import org.apache.gobblin.configuration.WorkUnitState; +import org.apache.gobblin.metrics.MetricContext; +import org.apache.gobblin.metrics.event.EventSubmitter; + + +/** + * A class that tracks KafkaExtractor statistics such as record decode time, #processed records, #undecodeable records etc. + * + */ +@Slf4j +public class KafkaExtractorStatsTracker { + // Constants for event submission + public static final String TOPIC = "topic"; + public static final String PARTITION = "partition"; + + private static final String GOBBLIN_KAFKA_NAMESPACE = "gobblin.kafka"; + private static final String KAFKA_EXTRACTOR_TOPIC_METADATA_EVENT_NAME = "KafkaExtractorTopicMetadata"; + private static final String LOW_WATERMARK = "lowWatermark"; + private static final String ACTUAL_HIGH_WATERMARK = "actualHighWatermark"; + private static final String EXPECTED_HIGH_WATERMARK = "expectedHighWatermark"; + private static final String ELAPSED_TIME = "elapsedTime"; + private static final String PROCESSED_RECORD_COUNT = "processedRecordCount"; + private static final String UNDECODABLE_MESSAGE_COUNT = "undecodableMessageCount"; + private static final String PARTITION_TOTAL_SIZE = "partitionTotalSize"; + private static final String AVG_RECORD_PULL_TIME = "avgRecordPullTime"; + private static final String AVG_RECORD_SIZE = "avgRecordSize"; + private static final String READ_RECORD_TIME = "readRecordTime"; + private static final String DECODE_RECORD_TIME = "decodeRecordTime"; + private static final String FETCH_MESSAGE_BUFFER_TIME = "fetchMessageBufferTime"; + private static final String LAST_RECORD_HEADER_TIMESTAMP = "lastRecordHeaderTimestamp"; + + @Getter + private final Map<KafkaPartition, ExtractorStats> statsMap; + private final Set<Integer> errorPartitions; + private final WorkUnitState workUnitState; + + //A global count of number of undecodeable messages encountered by the KafkaExtractor across all Kafka + //TopicPartitions. + @Getter + private int undecodableMessageCount = 0; + private List<KafkaPartition> partitions; + + public KafkaExtractorStatsTracker(WorkUnitState state, List<KafkaPartition> partitions) { Review comment: Actually, streaming extractor can get KafkaPartition the same way as KafkaExtractor does i.e. via KafkaUtils in the constructor. Further, Tag generation for tracking events needs the KafkaPartition objects. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services