metron-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nickwallen <...@git.apache.org>
Subject [GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Date Thu, 18 Aug 2016 16:29:09 GMT
Github user nickwallen commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/208#discussion_r75341662
  
    --- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/bolt/ProfileBuilderBolt.java
---
    @@ -0,0 +1,281 @@
    +/*
    + *
    + *  Licensed to the Apache Software Foundation (ASF) under one
    + *  or more contributor license agreements.  See the NOTICE file
    + *  distributed with this work for additional information
    + *  regarding copyright ownership.  The ASF licenses this file
    + *  to you under the Apache License, Version 2.0 (the
    + *  "License"); you may not use this file except in compliance
    + *  with the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + *  Unless required by applicable law or agreed to in writing, software
    + *  distributed under the License is distributed on an "AS IS" BASIS,
    + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + *  See the License for the specific language governing permissions and
    + *  limitations under the License.
    + *
    + */
    +
    +package org.apache.metron.profiler.bolt;
    +
    +import backtype.storm.Config;
    +import backtype.storm.Constants;
    +import backtype.storm.task.OutputCollector;
    +import backtype.storm.task.TopologyContext;
    +import backtype.storm.topology.OutputFieldsDeclarer;
    +import backtype.storm.tuple.Fields;
    +import backtype.storm.tuple.Tuple;
    +import backtype.storm.tuple.Values;
    +import org.apache.metron.common.bolt.ConfiguredProfilerBolt;
    +import org.apache.metron.common.configuration.profiler.ProfileConfig;
    +import org.apache.metron.common.dsl.ParseException;
    +import org.apache.metron.profiler.ProfileMeasurement;
    +import org.apache.metron.profiler.stellar.StellarExecutor;
    +import org.json.simple.JSONObject;
    +import org.json.simple.parser.JSONParser;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.IOException;
    +import java.util.Map;
    +
    +/**
    + * A bolt that is responsible for building a Profile.
    + *
    + * This bolt maintains the state required to build a Profile.  When the window
    + * period expires, the data is summarized as a ProfileMeasurement, all state is
    + * flushed, and the ProfileMeasurement is emitted.
    + *
    + * Each instance of this bolt is responsible for maintaining the state for a single
    + * Profile-Entity pair.
    + */
    +public class ProfileBuilderBolt extends ConfiguredProfilerBolt {
    +
    +  protected static final Logger LOG = LoggerFactory.getLogger(ProfileBuilderBolt.class);
    +
    +  /**
    +   * Executes Stellar code and maintains state across multiple invocations.
    +   */
    +  private StellarExecutor executor;
    +
    +  /**
    +   * The number of seconds between when the Profile is flushed.
    +   */
    +  private int flushFrequency;
    +
    +  /**
    +   * A ProfileMeasurement is created and emitted each window period.  A Profile
    +   * itself is composed of many ProfileMeasurements.
    +   */
    +  private transient ProfileMeasurement measurement;
    +
    +  /**
    +   * The definition of the Profile that the bolt is building.
    +   */
    +  private transient ProfileConfig profileConfig;
    +
    +  /**
    +   * Parses JSON messages.
    +   */
    +  private transient JSONParser parser;
    +
    +  private OutputCollector collector;
    +
    +  /**
    +   * @param zookeeperUrl The Zookeeper URL that contains the configuration data.
    +   */
    +  public ProfileBuilderBolt(String zookeeperUrl) {
    +    super(zookeeperUrl);
    +  }
    +
    +  /**
    +   * Defines the frequency at which the bolt will receive tick tuples.  Tick tuples are
    +   * used to control how often a profile is flushed.
    +   */
    +  @Override
    +  public Map<String, Object> getComponentConfiguration() {
    +    Config conf = new Config();
    +    conf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, getFlushFrequency());
    +    return conf;
    +  }
    +
    +  @Override
    +  public void prepare(Map stormConf, TopologyContext context, OutputCollector collector)
{
    +    super.prepare(stormConf, context, collector);
    +    this.collector = collector;
    +    this.parser = new JSONParser();
    +  }
    +
    +  @Override
    +  public void declareOutputFields(OutputFieldsDeclarer declarer) {
    +    // once the time window expires, a complete ProfileMeasurement is emitted
    +    declarer.declare(new Fields("measurement"));
    +  }
    +
    +  @Override
    +  public void execute(Tuple input) {
    +    try {
    +      doExecute(input);
    +      collector.ack(input);
    +
    +    } catch (Throwable e) {
    +      LOG.error("exception processing tuple: " + input, e);
    +      collector.reportError(e);
    --- End diff --
    
    Yes, it should be acked whether there is an exception or not.  The main failure scenario
is if someone creates a profile with a bad Stellar expression.  Retrying the tuple won't fix
that.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message