/** * Creates the {@link Values} attached to the outgoing tuple. * * @param route The route the message must take. * @return */ private Values createValues(MessageRoute route) { // the order here must match `declareOutputFields` return new Values(route.getMessage(), route.getTimestamp(), route.getEntity(), route.getProfileDefinition()); }
/** * Route a message based on the Profiler configuration. * @param input The input tuple on which to anchor. * @param message The telemetry message. * @param config The Profiler configuration. */ private void routeMessage(Tuple input, JSONObject message, ProfilerConfig config) { // emit a tuple for each 'route' List<MessageRoute> routes = router.route(message, config, getStellarContext()); for (MessageRoute route : routes) { Values values = createValues(route); collector.emit(input, values); LOG.debug("Found route for message; profile={}, entity={}, timestamp={}", route.getProfileDefinition().getProfile(), route.getEntity(), route.getTimestamp()); } LOG.debug("Found {} route(s) for message", routes.size()); }
@Override public String call(MessageRoute route) { ProfilePeriod period = ProfilePeriod.fromTimestamp(route.getTimestamp(), periodDuration, periodDurationUnits); return route.getProfileDefinition().getProfile() + "-" + route.getEntity() + "-" + period.getPeriod(); } }
/** * Retrieves the cached ProfileBuilder that is used to build and maintain the Profile. If none exists, * one will be created and returned. * * @param route The message route. * @param context The Stellar execution context. */ public ProfileBuilder getBuilder(MessageRoute route, Context context) throws ExecutionException { ProfileConfig profile = route.getProfileDefinition(); String entity = route.getEntity(); Function<Integer, ProfileBuilder> profileCreator = (k) -> new DefaultProfileBuilder.Builder() .withDefinition(profile) .withEntity(entity) .withPeriodDurationMillis(periodDurationMillis) .withContext(context) .build(); return activeCache.get(cacheKey(profile, entity), profileCreator); }