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

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

The newest version!
package com.wavefront.ingester;

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

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

import wavefront.report.ReportHistogram;

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

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

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

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

  @Override
  public ReportHistogram 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) {
    ReportHistogram histogram = new ReportHistogram();
    histogram.setCustomer(customerId);
    // if the point has a timestamp, this would be overriden
    histogram.setTimestamp(Clock.now());
    final StringParser parser = new StringParser(input);

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy