Github user HeartSaVioR commented on a diff in the pull request:
https://github.com/apache/storm/pull/1484#discussion_r66922591
--- Diff:
external/storm-opentsdb/src/main/java/org/apache/stom/opentsdb/bolt/OpenTsdbBolt.java
---
@@ -0,0 +1,172 @@
+/*
+ * 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.stom.opentsdb.bolt;
+
+import org.apache.stom.opentsdb.OpenTsdbMetricDatapoint;
+import org.apache.stom.opentsdb.client.ClientResponse;
+import org.apache.stom.opentsdb.client.OpenTsdbClient;
+import org.apache.storm.task.OutputCollector;
+import org.apache.storm.task.TopologyContext;
+import org.apache.storm.topology.OutputFieldsDeclarer;
+import org.apache.storm.topology.base.BaseRichBolt;
+import org.apache.storm.tuple.Tuple;
+import org.apache.storm.utils.BatchHelper;
+import org.apache.storm.utils.TupleUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Basic bolt implementation for storing timeseries datapoints to OpenTSDB.
+ *
+ * List of {@link OpenTsdbMetricDatapoint} is generated for each tuple
with the configured {@code tupleOpenTsdbDatapointMappers}.
+ * All these datapoints are batched till the given {@code batchSize} or
{@code flushIntervalInSeconds} is reached.
+ *
+ * Example topology:
+ *
+ */
+public class OpenTsdbBolt extends BaseRichBolt {
+ private static final Logger LOG =
LoggerFactory.getLogger(OpenTsdbBolt.class);
+
+ private final OpenTsdbClient.Builder openTsdbClientBuilder;
+ private final List<TupleOpenTsdbDatapointMapper>
tupleOpenTsdbDatapointMappers;
+ private int batchSize;
+ private int flushIntervalInSeconds;
+ private boolean failTupleForFailedMetrics;
+
+ private BatchHelper batchHelper;
+ private OpenTsdbClient openTsdbClient;
+ private Map<OpenTsdbMetricDatapoint, Tuple> metricPointsWithTuple =
new HashMap<>();
+ private OutputCollector collector;
+
+ public OpenTsdbBolt(OpenTsdbClient.Builder openTsdbClientBuilder,
List<TupleOpenTsdbDatapointMapper> tupleOpenTsdbDatapointMappers) {
+ this.openTsdbClientBuilder = openTsdbClientBuilder;
+ this.tupleOpenTsdbDatapointMappers = tupleOpenTsdbDatapointMappers;
+ }
+
+ public OpenTsdbBolt withFlushInterval(int flushIntervalInSeconds) {
+ this.flushIntervalInSeconds = flushIntervalInSeconds;
+ return this;
+ }
+
+ public OpenTsdbBolt withBatchSize(int batchSize) {
+ this.batchSize = batchSize;
+ return this;
+ }
+
+ /**
+ * When it is invoked, this bolt acks only the tuples which have
successful metrics stored into OpenTSDB and fails
+ * the respective tuples of the failed metrics.
+ *
+ * @return same insatcne by setting {@code failTupleForFailedMetrics}
to true
+ */
+ public OpenTsdbBolt failTupleForFailedMetrics() {
+ this.failTupleForFailedMetrics = true;
+ return this;
+ }
+
+ @Override
+ public void prepare(Map stormConf, TopologyContext context,
OutputCollector collector) {
+ this.collector = collector;
+ batchHelper = new BatchHelper(batchSize, collector);
+ openTsdbClient = openTsdbClientBuilder.build();
+ }
+
+ @Override
+ public void execute(Tuple tuple) {
+ try {
+ if (batchHelper.shouldHandle(tuple)) {
+ final List<OpenTsdbMetricDatapoint> metricDataPoints =
getMetricPoints(tuple);
+ for (OpenTsdbMetricDatapoint metricDataPoint :
metricDataPoints) {
+ metricPointsWithTuple.put(metricDataPoint, tuple);
+ }
+ batchHelper.addBatch(tuple);
--- End diff --
It just counts multiple metric datapoints into one since BatchHelper
handles batch via tuple. In fact, "count of mappers" data points are created
for each tuple.
Since target of batching is metric datapoints instead of tuples, it seems
not intuitive behavior.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---