Class CortexIo


  • @Experimental(SOURCE_SINK)
    public class CortexIo
    extends Object
    Provides write transforms (sinks) for writing to Cortex.

    Cortex requires that samples of a specific time series are written with increasing timestamps. The write transforms assign index numbers to output values that can be used as an additional metric label that make time series strictly increasing even in case of multiple panes for the same window and panes of later windows completing before panes of earlier windows.

    This class can provide two different kinds of sinks:

    Non-accumulating sink
    A sink that assigns unique index numbers to output values.
    Accumulating sink
    A sink that assigns unique index numbers to output values and additionally accumulates values of different panes before they are output.
    Both transforms use Beam's state mechanism to track written event timestamps. By doing so, index numbers can be derived that allow to disambiguate samples for the same event timestamps. The accumulating sink additionally uses Beam's timer mechanism to hold back values for accumulation and flushes values after a configured output delay.

    Note: The PaneAccumulator class can be used to achieve the same accumulation effect that the accumulating Cortex sink has. It makes sense to use the PaneAccumulator if several sinks can benefit from accumulated outputs. In case of a single sink the accumulating Cortex sink is preferable.

    Sinks are configured by the CortexIo.Write class and are implemented by subclasses of the CortexIo.WriteFn class. Sinks provide the following counter metrics in the "cortex" namespace:

    sample
    Counts the number of samples
    write
    Counts the number of sent write requests
    write_failure
    Counts the number of failed write requests (requests that resulted in an exception)
    response_failure
    Counts the number of Cortex responses with a non-success result code
    • Constructor Detail

      • CortexIo

        public CortexIo()
    • Method Detail

      • of

        public static <K,​V> CortexIo.Write<K,​V> of​(String writeUrl,
                                                               CortexIo.BuildTimeSeries<K,​V> build,
                                                               org.apache.beam.sdk.coders.Coder<K> keyCoder,
                                                               org.apache.beam.sdk.coders.Coder<V> valueCoder,
                                                               org.apache.beam.sdk.transforms.SerializableBiFunction<V,​V,​V> combiner,
                                                               org.joda.time.Duration accumulationDelay)
      • sanitizeMetricName

        public static String sanitizeMetricName​(String metricName)
      • sanitizeLabelName

        public static String sanitizeLabelName​(String labelName)