gobblin-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Work logged] (GOBBLIN-758) Use keys to push messages to kafka. Implemented Metric and Event reporters that push messages without serialization.
Date Fri, 03 May 2019 16:40:01 GMT

     [ https://issues.apache.org/jira/browse/GOBBLIN-758?focusedWorklogId=236929&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-236929
]

ASF GitHub Bot logged work on GOBBLIN-758:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 03/May/19 16:39
            Start Date: 03/May/19 16:39
    Worklog Time Spent: 10m 
      Work Description: zxcware commented on pull request #2622: [GOBBLIN-758] Added new reporters
to emit MetricReport and GobblinTrackingEvent without serializing them. Also added random
key generator for reporters.
URL: https://github.com/apache/incubator-gobblin/pull/2622#discussion_r280843150
 
 

 ##########
 File path: gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/metrics/kafka/KeyValueEventObjectReporter.java
 ##########
 @@ -0,0 +1,173 @@
+/*
+ * 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.metrics.kafka;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+import java.util.Random;
+
+import org.apache.avro.generic.GenericRecord;
+import org.apache.commons.lang3.tuple.Pair;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
+import com.typesafe.config.Config;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.gobblin.configuration.ConfigurationKeys;
+import org.apache.gobblin.metrics.GobblinTrackingEvent;
+import org.apache.gobblin.metrics.MetricContext;
+import org.apache.gobblin.metrics.reporter.EventReporter;
+import org.apache.gobblin.util.AvroUtils;
+import org.apache.gobblin.util.ConfigUtils;
+
+
+@Slf4j
+public class KeyValueEventObjectReporter extends EventReporter {
+  private static final String PUSHER_CONFIG = "pusherConfig";
+  private static final String PUSHER_CLASS = "pusherClass";
+  private static final String PUSHER_KEYS = "pusherKeys";
+
+  protected Optional<List<String>> keys = Optional.absent();
+  protected final String randomKey;
+  protected KeyValuePusher pusher;
+  protected Optional<Map<String, String>> namespaceOverride;
+  protected final String topic;
+
+  public KeyValueEventObjectReporter(Builder<?> builder) {
+    super(builder);
+
+    this.topic = builder.topic;
+    this.namespaceOverride = builder.namespaceOverride;
+
+    Config config = builder.config.get();
+    Config pusherConfig = ConfigUtils.getConfigOrEmpty(config, PUSHER_CONFIG).withFallback(config);
+    String pusherClassName =
+        ConfigUtils.getString(config, PUSHER_CLASS, PusherUtils.DEFAULT_KEY_VALUE_PUSHER_CLASS_NAME);
+    this.pusher =
+        PusherUtils.getKeyValuePusher(pusherClassName, builder.brokers, builder.topic, Optional.of(pusherConfig));
+    this.closer.register(this.pusher);
+
+    randomKey = String.valueOf(new Random().nextInt(100));
+    if (config.hasPath(PUSHER_KEYS)) {
+      List<String> keys = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(config.getString(PUSHER_KEYS));
+      this.keys = Optional.of(keys);
+    } else {
+      log.warn("Key not assigned from config. Please set it with property {}",
+          ConfigurationKeys.METRICS_REPORTING_EVENTS_KAFKAPUSHERKEYS);
+      log.warn("Using generated number " + randomKey + " as key");
+    }
+  }
+
+  @Override
+  public void reportEventQueue(Queue<GobblinTrackingEvent> queue) {
+    log.info("Emitting report using KeyValueEventObjectReporter");
+
+    List<Pair<String, GenericRecord>> events = Lists.newArrayList();
+    GobblinTrackingEvent event;
+
+    while (null != (event = queue.poll())) {
+      GenericRecord record = AvroUtils.overrideNameAndNamespace(event, this.topic, this.namespaceOverride);
+      events.add(Pair.of(buildKey(event), record));
+    }
+
+    if (!events.isEmpty()) {
+      this.pusher.pushKeyValueMessages(events);
+    }
+  }
+
+  private String buildKey(GobblinTrackingEvent event) {
+
+    String key = randomKey;
+    if (this.keys.isPresent()) {
+      StringBuilder keyBuilder = new StringBuilder();
+      for (String keyPart : keys.get()) {
+        Optional value = AvroUtils.getFieldValue(event, keyPart);
+        if (value.isPresent()) {
+          keyBuilder.append(value.get().toString());
+        } else {
+          log.error("{} not found in the GobblinTrackingEvent. Setting key to {}", keyPart,
key);
+          keyBuilder = null;
+          break;
+        }
+      }
+
+      key = (keyBuilder == null) ? key : keyBuilder.toString();
 
 Review comment:
   keyBuilder will never be null, right?
 
----------------------------------------------------------------
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:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 236929)
    Time Spent: 40m  (was: 0.5h)

> Use keys to push messages to kafka. Implemented Metric and Event reporters that push
messages without serialization.
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: GOBBLIN-758
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-758
>             Project: Apache Gobblin
>          Issue Type: Improvement
>            Reporter: Vikram Bohra
>            Priority: Major
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> This ticket introduces the following changes.
> 1) It reduces the number of connections to Kafka by using a randomly generated key for
each instance of the reporter.
> 2) Introduces a KeyValuePusher interface that provides a cleaner way to push key value
messages to kafka.
> 3) Default implementation of the above interface for kafka. 
> 4) New Reporters for reporting GobblinTrackingEvent and MetricReport without serializing
them.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message