Search in sources :

Example 1 with OpenTsdbMetricDatapoint

use of org.apache.storm.opentsdb.OpenTsdbMetricDatapoint in project storm by apache.

the class OpenTsdbBolt method execute.

@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);
        }
        if (batchHelper.shouldFlush()) {
            LOG.debug("Sending metrics of size [{}]", metricPointsWithTuple.size());
            ClientResponse.Details clientResponse = openTsdbClient.writeMetricPoints(metricPointsWithTuple.keySet());
            if (failTupleForFailedMetrics && clientResponse != null && clientResponse.getFailed() > 0) {
                final List<ClientResponse.Details.Error> errors = clientResponse.getErrors();
                LOG.error("Some of the metric points failed with errors: [{}]", clientResponse);
                if (errors != null && !errors.isEmpty()) {
                    Set<Tuple> failedTuples = new HashSet<>();
                    for (ClientResponse.Details.Error error : errors) {
                        final Tuple failedTuple = metricPointsWithTuple.get(error.getDatapoint());
                        if (failedTuple != null) {
                            failedTuples.add(failedTuple);
                        }
                    }
                    for (Tuple batchedTuple : batchHelper.getBatchTuples()) {
                        if (failedTuples.contains(batchedTuple)) {
                            collector.fail(batchedTuple);
                        } else {
                            collector.ack(batchedTuple);
                        }
                    }
                } else {
                    throw new RuntimeException("Some of the metric points failed with details: " + errors);
                }
            } else {
                LOG.debug("Acknowledging batched tuples");
                batchHelper.ack();
            }
            metricPointsWithTuple.clear();
        }
    } catch (Exception e) {
        batchHelper.fail(e);
        metricPointsWithTuple.clear();
    }
}
Also used : ClientResponse(org.apache.storm.opentsdb.client.ClientResponse) OpenTsdbMetricDatapoint(org.apache.storm.opentsdb.OpenTsdbMetricDatapoint) Tuple(org.apache.storm.tuple.Tuple) HashSet(java.util.HashSet)

Example 2 with OpenTsdbMetricDatapoint

use of org.apache.storm.opentsdb.OpenTsdbMetricDatapoint in project storm by apache.

the class OpenTsdbState method update.

public void update(List<TridentTuple> tridentTuples, TridentCollector collector) {
    try {
        List<OpenTsdbMetricDatapoint> metricDataPoints = new ArrayList<>();
        for (TridentTuple tridentTuple : tridentTuples) {
            for (ITupleOpenTsdbDatapointMapper tupleOpenTsdbDatapointMapper : tupleMetricPointMappers) {
                metricDataPoints.add(tupleOpenTsdbDatapointMapper.getMetricPoint(tridentTuple));
            }
        }
        final ClientResponse.Details details = openTsdbClient.writeMetricPoints(metricDataPoints);
        if (details != null && (details.getFailed() > 0)) {
            final String errorMsg = "Failed in writing metrics to TSDB with details: " + details;
            LOG.error(errorMsg);
            throw new RuntimeException(errorMsg);
        }
    } catch (Exception e) {
        collector.reportError(e);
        throw new FailedException(e);
    }
}
Also used : ClientResponse(org.apache.storm.opentsdb.client.ClientResponse) OpenTsdbMetricDatapoint(org.apache.storm.opentsdb.OpenTsdbMetricDatapoint) FailedException(org.apache.storm.topology.FailedException) ArrayList(java.util.ArrayList) ITupleOpenTsdbDatapointMapper(org.apache.storm.opentsdb.bolt.ITupleOpenTsdbDatapointMapper) FailedException(org.apache.storm.topology.FailedException) TridentTuple(org.apache.storm.trident.tuple.TridentTuple)

Aggregations

OpenTsdbMetricDatapoint (org.apache.storm.opentsdb.OpenTsdbMetricDatapoint)2 ClientResponse (org.apache.storm.opentsdb.client.ClientResponse)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ITupleOpenTsdbDatapointMapper (org.apache.storm.opentsdb.bolt.ITupleOpenTsdbDatapointMapper)1 FailedException (org.apache.storm.topology.FailedException)1 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)1 Tuple (org.apache.storm.tuple.Tuple)1