Search in sources :

Example 1 with TaggedData

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

the class TaggingStage method tagData.

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

Aggregations

Metrics (io.mantisrx.common.metrics.Metrics)1 MetricGroupId (io.mantisrx.common.metrics.spectator.MetricGroupId)1 Query (io.mantisrx.mql.jvm.core.Query)1 TaggedData (io.mantisrx.sourcejob.synthetic.core.TaggedData)1 ArrayList (java.util.ArrayList)1