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

org.opentripplanner.updater.trip.metrics.TripUpdateMetrics Maven / Gradle / Ivy

package org.opentripplanner.updater.trip.metrics;

import io.micrometer.core.instrument.Tag;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.opentripplanner.updater.trip.UpdateResult;
import org.opentripplanner.updater.trip.UrlUpdaterParameters;
import org.opentripplanner.util.OTPFeature;

public class TripUpdateMetrics {

  public static final Consumer NOOP = ignored -> {};
  protected List baseTags;

  TripUpdateMetrics(UrlUpdaterParameters parameters) {
    this.baseTags =
      List.of(
        Tag.of("configRef", parameters.getConfigRef()),
        Tag.of("url", parameters.getUrl()),
        Tag.of("feedId", parameters.getFeedId())
      );
  }

  public static Consumer batch(UrlUpdaterParameters parameters) {
    return getConsumer(() -> {
      var metrics = new BatchTripUpdateMetrics(parameters);
      return metrics::setGauges;
    });
  }

  public static Consumer streaming(UrlUpdaterParameters parameters) {
    return getConsumer(() -> {
      var metrics = new StreamingTripUpdateMetrics(parameters);
      return metrics::setCounters;
    });
  }

  private static Consumer getConsumer(Supplier> maker) {
    if (OTPFeature.ActuatorAPI.isOn()) {
      return maker.get();
    } else {
      return NOOP;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy