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

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

The newest version!
package com.wavefront.ingester;

import com.wavefront.common.Clock;
import com.wavefront.data.ParseException;

import wavefront.report.ReportMetric;

import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Supplier;

/**
 * Builder pattern for creating new ingestion formats. Inspired by the date time formatters in
 * Joda.
 *
 * @author Clement Pang ([email protected]).
 */
public class ReportMetricIngesterFormatter extends AbstractIngesterFormatter {

  private ReportMetricIngesterFormatter(List> elements) {
    super(elements);
  }

  public static class ReportMetricIngesterFormatBuilder
      extends IngesterFormatBuilder {
    @Override
    public ReportMetricIngesterFormatter build() {
      return new ReportMetricIngesterFormatter(elements);
    }
  }

  public static IngesterFormatBuilder newBuilder() {
    return new ReportMetricIngesterFormatBuilder();
  }

  @Override
  public ReportMetric drive(String input, Supplier defaultHostNameSupplier,
                            String customerId, @Nullable List customSourceTags,
                            @Nullable List customLogTimestampTags, @Nullable List customLogMessageTags,
                            List customLogApplicationTags, List customLogServiceTags,
                            @Nullable List customLogLevelTags, @Nullable List customLogExceptionTags, @Nullable IngesterContext ingesterContext) {
    ReportMetric point = new ReportMetric();
    point.setCustomer(customerId);
    // if the point has a timestamp, this would be overriden
    point.setTimestamp(Clock.now());
    final StringParser parser = new StringParser(input);

    for (FormatterElement element : elements) {
      element.consume(parser, point);
    }
    if (parser.hasNext()) {
      throw new ParseException("Unexpected extra input: " + parser.next());
    }

    String host = AbstractIngesterFormatter.getHostAndNormalizeTags(point.getAnnotations(), customSourceTags, true);
    if (host == null) {
      if (defaultHostNameSupplier == null) {
        host = "unknown";
      } else {
        host = defaultHostNameSupplier.get();
      }
    }
    point.setHost(host);
    return point;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy