Search in sources :

Example 1 with TaggedData

use of io.mantisrx.sourcejob.kafka.core.TaggedData in project mantis by Netflix.

the class AbstractAckableTaggingStage method tagData.

@SuppressWarnings("unchecked")
protected List<TaggedData> tagData(Map<String, Object> d, Context context) {
    List<TaggedData> taggedDataList = new ArrayList<>();
    boolean metaEvent = isMetaEvent(d);
    Metrics metrics = context.getMetricsRegistry().getMetric("mql");
    Collection<Query> queries = MQLQueryManager.getInstance().getRegisteredQueries();
    Iterator<Query> it = queries.iterator();
    while (it.hasNext()) {
        Query query = it.next();
        try {
            if (metaEvent) {
                TaggedData tg = new TaggedData(d);
                tg.addMatchedClient(query.getSubscriptionId());
                taggedDataList.add(tg);
            } else if (query.matches(d)) {
                Map<String, Object> projected = query.project(d);
                projected.put(MANTIS_META_SOURCE_NAME, d.get(MANTIS_META_SOURCE_NAME));
                projected.put(MANTIS_META_SOURCE_TIMESTAMP, d.get(MANTIS_META_SOURCE_TIMESTAMP));
                TaggedData tg = new TaggedData(projected);
                tg.addMatchedClient(query.getSubscriptionId());
                taggedDataList.add(tg);
            }
        } catch (Exception ex) {
            if (ex instanceof ClassNotFoundException) {
                logger.error("Error loading MQL: " + ex.getMessage());
                ex.printStackTrace();
                metrics.getCounter(MQL_CLASSLOADER_ERROR).increment();
            } else {
                ex.printStackTrace();
                metrics.getCounter(MQL_FAILURE).increment();
                logger.error("MQL Error: " + ex.getMessage());
                logger.error("MQL Query: " + query.getRawQuery());
                logger.error("MQL Datum: " + d);
            }
        } catch (Error e) {
            metrics.getCounter(MQL_FAILURE).increment();
            if (!errorLogged.get()) {
                logger.error("caught Error when processing MQL {} on {}", query.getRawQuery(), d.toString(), e);
                errorLogged.set(true);
            }
        }
    }
    return taggedDataList;
}
Also used : Metrics(io.mantisrx.common.metrics.Metrics) Query(io.mantisrx.mql.jvm.core.Query) ArrayList(java.util.ArrayList) TaggedData(io.mantisrx.sourcejob.kafka.core.TaggedData) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Metrics (io.mantisrx.common.metrics.Metrics)1 Query (io.mantisrx.mql.jvm.core.Query)1 TaggedData (io.mantisrx.sourcejob.kafka.core.TaggedData)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1