All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.wavefront.ingester.GraphiteDecoder Maven / Gradle / Ivy

The newest version!
package com.wavefront.ingester;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.wavefront.data.ParseException;

import java.util.List;
import java.util.function.Supplier;
import java.util.regex.Pattern;

import wavefront.report.ReportPoint;

import javax.annotation.Nullable;

/**
 * DEPRECATED: use {@link ReportMetricDecoder} instead.
 *
 * Graphite decoder that takes in a point of the type:
 *
 * [metric] [value] [timestamp] [annotations]
 *
 * @author Clement Pang ([email protected]).
 */
@Deprecated
public class GraphiteDecoder implements Decoder {

  private static final Pattern CUSTOMERID = Pattern.compile("[a-z]+");

  private final ReportableEntityDecoder pointDecoder;

  public GraphiteDecoder(List customSourceTags) {
    this("unknown", customSourceTags);
  }

  public GraphiteDecoder(String hostName, List customSourceTags) {
    this(() -> hostName, customSourceTags);
  }

  public GraphiteDecoder(@Nullable Supplier hostNameSupplier,
                         List customSourceTags) {
    this.pointDecoder = new ReportPointDecoder(hostNameSupplier, customSourceTags);
  }

  @Override
  public void decodeReportPoints(String msg, List out, String customerId) {
    pointDecoder.decode(msg, out, customerId);
  }

  @Override
  public void decodeReportPoints(String msg, List out, String customerId,
                                 IngesterContext ctx) {
    pointDecoder.decode(msg, out, customerId, null);
  }

  @Override
  public void decodeReportPoints(String msg, List out) {
    List output = Lists.newArrayList();
    decodeReportPoints(msg, output, "dummy");
    if (!output.isEmpty()) {
      for (ReportPoint rp : output) {
        String metricName = rp.getMetric();
        List metricParts = Lists.newArrayList(Splitter.on(".").split(metricName));
        if (metricParts.size() <= 1) {
          throw new ParseException("Metric name does not contain a customer id: " + metricName);
        }
        String customerId = metricParts.get(0);
        if (CUSTOMERID.matcher(customerId).matches()) {
          metricName = Joiner.on(".").join(metricParts.subList(1, metricParts.size()));
        }
        out.add(ReportPoint.newBuilder(rp).setMetric(metricName).setTable(customerId).build());
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy