You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metron.apache.org by nickwallen <gi...@git.apache.org> on 2016/08/10 23:48:15 UTC
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
GitHub user nickwallen opened a pull request:
https://github.com/apache/incubator-metron/pull/208
METRON-309 Create a normalcy profiler
### [METRON-309](https://issues.apache.org/jira/browse/METRON-309)
Created a normalcy profiler, otherwise known as the Metron Profiler.
The Profiler is a feature extraction mechanism that can generate a profile describing the behavior of an entity on a network. An entity might be a server, user, subnet or application. Once a profile has been generated defining what normal behavior looks-like, it can be used to build models that identify anomalous behavior.
This is achieved by summarizing the streaming telemetry data consumed by Metron over sliding windows. A summary statistic is applied to the data received within a given window. Collecting this summary across many windows results in a time series that is useful for analysis.
### Changes
This PR contains the following high-level changes to Metron.
* A Storm topology that generates Profiles. `metron-analytics/metron-profiler`
* Changes to Ansible to deploy the Profiler topology. `metron-deployment`
* A new bolt and associated tooling to perform HBase writes from a Storm topology. `metron-platform/metron-hbase`
* Additions to the Stellar language to provide arithmetic and control flow logic required to generate Profiles. `metron-platform/metron-common`
### Testing
Follow the instructions contained in the [README](https://github.com/nickwallen/incubator-metron/tree/METRON-309/metron-analytics/metron-profiler#getting-started) to get your very first Profile running.
### Documentation
* Documentation for the Profiler is contained within the [README](https://github.com/nickwallen/incubator-metron/blob/METRON-309/metron-analytics/metron-profiler/README.md).
* The code itself contains plenty of comments and Javadocs.
* The design document is attached to the [JIRA](https://issues.apache.org/jira/browse/METRON-309).
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/nickwallen/incubator-metron METRON-309
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-metron/pull/208.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #208
----
commit a77fe3e91601dcf1698271aad1b00e687038b1ed
Author: Nick Allen <ni...@nickallen.org>
Date: 2016-07-29T20:53:49Z
METRON-309 Create a normalcy profiler
----
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75336671
--- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/stellar/DefaultStellarExecutor.java ---
@@ -0,0 +1,116 @@
+/*
+ *
+ * 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.stellar;
+
+import org.apache.metron.common.dsl.MapVariableResolver;
+import org.apache.metron.common.dsl.ParseException;
+import org.apache.metron.common.dsl.VariableResolver;
+import org.apache.metron.common.stellar.StellarPredicateProcessor;
+import org.apache.metron.common.stellar.StellarProcessor;
+import org.json.simple.JSONObject;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * The default implementation of a StellarExecutor.
+ */
+public class DefaultStellarExecutor implements StellarExecutor, Serializable {
+
+ /**
+ * The current state of the Stellar execution environment.
+ */
+ private Map<String, Object> state;
+
+ public DefaultStellarExecutor() {
+ clearState();
+ }
+
+ /**
+ * @param initialState Initial state loaded into the execution environment.
+ */
+ public DefaultStellarExecutor(Map<String, Object> initialState) {
+ this.state = new HashMap<>(initialState);
+ }
+
+ @Override
+ public Map<String, Object> getState() {
+ return new HashMap<>(state);
+ }
+
+ /**
+ * Execute an expression and assign the result to a variable.
+ *
+ * @param variable The variable name to assign to.
+ * @param expression The expression to execute.
+ * @param message The message that provides additional context for the expression.
+ */
+ @Override
+ public void assign(String variable, String expression, JSONObject message) {
+ Object result = execute(expression, message);
+ state.put(variable, result);
+ }
+
+ /**
+ * Execute a Stellar expression and returns the result.
+ *
+ * @param expr The expression to execute.
+ * @param message The message that is accessible when Stellar is executed.
+ * @param clazz The expected class of the expression's result.
+ * @param <T> The expected class of the expression's result.
+ */
+ @Override
+ public <T> T execute(String expr, JSONObject message, Class<T> clazz) {
+ Object result = execute(expr, message);
+
+ // ensure the result type is as expected
+ if (clazz.isAssignableFrom(result.getClass())) {
+ return (T) result;
+
+ } else {
+ throw new RuntimeException(String.format("Unexpected type: expected=%s, actual=%s, expression=%s",
--- End diff --
Yes, I think that is a good idea. If I am adding two integers and I am expecting a float, it would be useful to have that just work.
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75323693
--- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/bolt/ProfileHBaseMapper.java ---
@@ -0,0 +1,136 @@
+/*
+ *
+ * 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.tuple.Tuple;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.metron.profiler.ProfileMeasurement;
+import org.apache.storm.hbase.bolt.mapper.HBaseMapper;
+import org.apache.storm.hbase.common.ColumnList;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Calendar;
+
+/**
+ * An HbaseMapper that defines how a ProfileMeasurement is persisted within an HBase table.
+ */
+public class ProfileHBaseMapper implements HBaseMapper {
+
+ /**
+ * A salt is prepended to the row key to help prevent hotspotting. This constant is used
+ * to generate the salt. Ideally, this constant should be roughly equal to the number of
+ * nodes in the Hbase cluster.
+ */
+ private int saltDivisor = 10;
+
+ /**
+ * The name of the column family.
+ */
+ private String columnFamily;
+
+ public ProfileHBaseMapper() {
+ setColumnFamily("cfProfile");
--- End diff --
Generally people try to keep the CF name super short (often 1 character) because it's replicated with every data point (see http://hbase.apache.org/0.94/book/rowkey.design.html). Can we call it 'P' for profile?
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75324056
--- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/bolt/ProfileSplitterBolt.java ---
@@ -0,0 +1,158 @@
+/*
+ *
+ * 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.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.configuration.profiler.ProfilerConfig;
+import org.apache.metron.profiler.stellar.StellarExecutor;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+
+/**
+ * The bolt responsible for filtering incoming messages and directing
+ * each to the one or more bolts responsible for building a Profile. Each
+ * message may be needed by 0, 1 or even many Profiles.
+ */
+public class ProfileSplitterBolt extends ConfiguredProfilerBolt {
+
+ protected static final Logger LOG = LoggerFactory.getLogger(ProfileSplitterBolt.class);
+
+ private OutputCollector collector;
+
+ /**
+ * JSON parser.
+ */
+ private transient JSONParser parser;
+
+ /**
+ * Executes Stellar code.
+ */
+ private StellarExecutor executor;
+
+ /**
+ * @param zookeeperUrl The Zookeeper URL that contains the configuration for this bolt.
+ */
+ public ProfileSplitterBolt(String zookeeperUrl) {
+ super(zookeeperUrl);
+ }
+
+ @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 execute(Tuple input) {
+ try {
+ doExecute(input);
+
+ } catch (IllegalArgumentException | ParseException | UnsupportedEncodingException e) {
+ LOG.error("Unexpected exception", e);
--- End diff --
Can you bubble the exception message up like `"Unexpected exception: e.getMessage()`?
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75326025
--- Diff: metron-platform/metron-common/src/main/java/org/apache/metron/common/configuration/ConfigurationsUtils.java ---
@@ -247,19 +301,24 @@ public static void uploadConfigsToZookeeper(String globalConfigPath, String pars
}
public static void visitConfigs(CuratorFramework client, ConfigurationVisitor callback) throws Exception {
- visitConfigs(client, callback, ConfigurationType.GLOBAL);
- visitConfigs(client, callback, ConfigurationType.PARSER);
- visitConfigs(client, callback, ConfigurationType.ENRICHMENT);
+ visitConfigs(client, callback, GLOBAL);
--- End diff --
Not a big deal, but maybe we could make visitConfigs take a vararg of ConfigurationType and then pass in `GLOBAL`, `PARSER`, `ENRICHMENT`, `PROFILER` in as args
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75371643
--- Diff: metron-analytics/metron-profiler/src/main/config/profiler.properties ---
@@ -0,0 +1,36 @@
+#
+#
+# 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.
+#
+#
+
+##### Storm #####
+
+profiler.workers=1
+profiler.executors=0
+profiler.input.topic=indexing
+profiler.flush.interval.seconds=900
+profiler.hbase.salt.divisor=10
--- End diff --
I am thinking that we have a lot of performance testing to do before we can intelligently set a default value.
There is some guidance on setting this value in ProfileHBaseMapper. I can certainly add some additional docs here too.
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75317251
--- Diff: metron-analytics/metron-profiler/README.md ---
@@ -0,0 +1,229 @@
+# Metron Profiler
+
+The Profiler is a feature extraction mechanism that can generate a profile describing the behavior of an entity on a network. An entity might be a server, user, subnet or application. Once a profile has been generated defining what normal behavior looks-like, models can be built that identify anomalous behavior.
+
+This is achieved by summarizing the streaming telemetry data consumed by Metron over sliding windows. A summary statistic is applied to the data received within a given window. Collecting this summary across many windows results in a time series that is useful for analysis.
+
+## Usage
+
+Any field contained within a message can be used to generate a profile. A profile can even be produced from combining fields that originate in different data sources. A user has considerable power to transform the data used in a profile by leveraging the Stellar language. A user only need configure the desired profiles in Zookeeper and ensure that the Profiler topology is running.
+
+### Configuration
+
+The Profiler configuration requires a JSON-formatted set of elements, many of which can contain Stellar code. The configuration contains the following elements.
+
+* `profile` A unique name identifying the profile.
+* `foreach` A separate profile is maintained for each of these. This is effectively the entity that the profile is describing. For example, if `ip_src_addr` then a separate profile would be maintained for each unique IP source address.
--- End diff --
Should we indicate that these are stellar statements and link to the language ref in metron-common's README?
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75335900
--- Diff: metron-analytics/metron-profiler/src/test/config/zookeeper/readme-example-1/profiler.json ---
@@ -0,0 +1,17 @@
+{
+ "inputTopic": "indexing",
+ "profiles": [
+ {
+ "profile": "example1",
+ "foreach": "ip_src_addr",
+ "onlyif": "protocol == 'HTTP'",
+ "init": {
+ "total_bytes": 0.0
--- End diff --
Yes, the values within the 'init' block are executed as Stellar expressions. See ProfileBuilderBolt.init(...).
---
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.
---
[GitHub] incubator-metron issue #208: METRON-309 Create a normalcy profiler
Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on the issue:
https://github.com/apache/incubator-metron/pull/208
Yeah, I can add some read functionality as part of a separate PR, if you think that makes sense.
---
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.
---
[GitHub] incubator-metron issue #208: METRON-309 Create a normalcy profiler
Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on the issue:
https://github.com/apache/incubator-metron/pull/208
Changes to the [project's by-laws](https://cwiki.apache.org/confluence/display/METRON/Apache+Metron+Bylaws) recently passed. Only lazy consensus needed for pull requests. This PR has already reached that threshold. About to merge.
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/incubator-metron/pull/208
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75356014
--- Diff: metron-analytics/metron-profiler/src/main/config/profiler.properties ---
@@ -0,0 +1,36 @@
+#
+#
+# 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.
+#
+#
+
+##### Storm #####
+
+profiler.workers=1
+profiler.executors=0
+profiler.input.topic=indexing
+profiler.flush.interval.seconds=900
+profiler.hbase.salt.divisor=10
--- End diff --
Can we have a larger salt divisor? Shouldn't it be bigger than the size of the cluster (in nodes) or am I thinking about this wrong? We might want some rough guidance around choosing the right one in the docs too.
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75339890
--- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/bolt/ProfileHBaseMapper.java ---
@@ -0,0 +1,136 @@
+/*
+ *
+ * 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.tuple.Tuple;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.metron.profiler.ProfileMeasurement;
+import org.apache.storm.hbase.bolt.mapper.HBaseMapper;
+import org.apache.storm.hbase.common.ColumnList;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Calendar;
+
+/**
+ * An HbaseMapper that defines how a ProfileMeasurement is persisted within an HBase table.
+ */
+public class ProfileHBaseMapper implements HBaseMapper {
+
+ /**
+ * A salt is prepended to the row key to help prevent hotspotting. This constant is used
+ * to generate the salt. Ideally, this constant should be roughly equal to the number of
+ * nodes in the Hbase cluster.
+ */
+ private int saltDivisor = 10;
+
+ /**
+ * The name of the column family.
+ */
+ private String columnFamily;
+
+ public ProfileHBaseMapper() {
+ setColumnFamily("cfProfile");
--- End diff --
Yes, makes sense. Done.
---
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.
---
[GitHub] incubator-metron issue #208: METRON-309 Create a normalcy profiler
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:
https://github.com/apache/incubator-metron/pull/208
So, regarding the salt divisor, I completely agree that we're going to need to performance test. Maybe a blurb in the docs around what its intent is.
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75353884
--- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/bolt/ProfileSplitterBolt.java ---
@@ -0,0 +1,161 @@
+/*
+ *
+ * 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.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.configuration.profiler.ProfilerConfig;
+import org.apache.metron.profiler.stellar.StellarExecutor;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+
+import static java.lang.String.format;
+
+/**
+ * The bolt responsible for filtering incoming messages and directing
+ * each to the one or more bolts responsible for building a Profile. Each
+ * message may be needed by 0, 1 or even many Profiles.
+ */
+public class ProfileSplitterBolt extends ConfiguredProfilerBolt {
+
+ protected static final Logger LOG = LoggerFactory.getLogger(ProfileSplitterBolt.class);
+
+ private OutputCollector collector;
+
+ /**
+ * JSON parser.
+ */
+ private transient JSONParser parser;
+
+ /**
+ * Executes Stellar code.
+ */
+ private StellarExecutor executor;
+
+ /**
+ * @param zookeeperUrl The Zookeeper URL that contains the configuration for this bolt.
+ */
+ public ProfileSplitterBolt(String zookeeperUrl) {
+ super(zookeeperUrl);
+ }
+
+ @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 execute(Tuple input) {
+ try {
+ doExecute(input);
+
+ } catch (IllegalArgumentException | ParseException | UnsupportedEncodingException e) {
+ LOG.error(format("Unexpected failure: message='%s', tuple='%s'", e.getMessage(), input), e);
+ collector.reportError(e);
+
+ } finally {
+ collector.ack(input);
+ }
+ }
+
+ private void doExecute(Tuple input) throws ParseException, UnsupportedEncodingException {
+
+ // retrieve the input message
+ byte[] data = input.getBinary(0);
+ JSONObject message = (JSONObject) parser.parse(new String(data, "UTF8"));
+
+ // ensure there is a valid profiler configuration
+ ProfilerConfig config = getProfilerConfig();
+ if(config == null) {
+ throw new IllegalArgumentException("Fatal: Unable to find valid profiler definition");
+ }
+
+ // apply the message to each of the profile definitions
+ for (ProfileConfig profile: config.getProfiles()) {
+ applyProfile(profile, input, message);
+ }
+ }
+
+ /**
+ * Applies a message to a Profile definition.
+ * @param profile The profile definition.
+ * @param input The input tuple that delivered the message.
+ * @param message The message that may be needed by the profile.
+ */
+ private void applyProfile(ProfileConfig profile, Tuple input, JSONObject message) throws ParseException, UnsupportedEncodingException {
+
+ // is this message needed by this profile?
+ String onlyIf = profile.getOnlyif();
+ if (executor.execute(onlyIf, message, Boolean.class)) {
+
+ // what is the name of the entity in this message?
+ String entity = executor.execute(profile.getForeach(), message, String.class);
+
+ // emit a message for the bolt responsible for building this profile
+ collector.emit(input, new Values(entity, profile, copyMessage(input)));
--- End diff --
Are you doing a deep copy here because you're caching off the tuple and modifying it after it's emitted?
---
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.
---
[GitHub] incubator-metron issue #208: METRON-309 Create a normalcy profiler
Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on the issue:
https://github.com/apache/incubator-metron/pull/208
@mmiklavc I ran into some issues talking to HBase with the new Profiler topology in the current Quick Dev environment. Once I did the old-school injection of the site resources everything worked fine.
```
cd /etc/hbase/conf && jar -uf /usr/metron/0.2.0BETA/lib/metron-profiler-0.2.0BETA.jar hbase-site.xml
cd /etc/hadoop/conf && jar -uf /usr/metron/0.2.0BETA/lib/metron-profiler-0.2.0BETA.jar core-site.xml
cd /etc/hadoop/conf && jar -uf /usr/metron/0.2.0BETA/lib/metron-profiler-0.2.0BETA.jar hdfs-site.xml
```
I am wondering if this is because of [METRON-356](https://github.com/nickwallen/incubator-metron/commit/b9282b438422d56fac23301dc854a39ae7d83a83). Could the current version of Quick Dev be broken because we removed the site injection from Ansible, but have not updated the Vagrant box for Quick Dev out in Atlas?
If so, it is not really a problem. I just want to make sure that I fully understand the root cause for the issue that I am seeing.
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r74491645
--- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/bolt/ProfileBuilderBolt.java ---
@@ -0,0 +1,265 @@
+/*
+ *
+ * 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.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 (IOException e) {
+ LOG.error("exception: {}", e);
+ collector.reportError(e);
+ }
+ }
+
+ /**
+ * Update the execution environment based on data contained in the
+ * message. If the tuple is a tick tuple, then flush the profile
+ * and reset the execution environment.
+ * @param input The tuple to execute.
+ */
+ private void doExecute(Tuple input) throws IOException {
+
+ if(!isTickTuple(input)) {
+
+ // if this is the first tuple in a window period, initialization is needed
+ if (!isInitialized()) {
+ init(input);
+ }
+
+ // update the profile with data from a new message
+ update(input);
+
+ } else {
+
+ // flush the profile - can only flush if it has been initialized
+ if(isInitialized()) {
+ flush(input);
+ }
+ }
+ }
+
+ /**
+ * Initialize the bolt. Occurs when the first tuple is received at the start
+ * of each window period.
+ * @param input The input tuple
+ */
+ private void init(Tuple input) throws IOException {
+
+ // save the profile definition - needed later during a flush
+ profileConfig = (ProfileConfig) input.getValueByField("profile");
+
+ // create the measurement which will be saved at the end of the window period
+ measurement = new ProfileMeasurement();
+ measurement.setStart(getTimestamp());
+ measurement.setEntity(input.getStringByField("entity"));
+ measurement.setProfileName(profileConfig.getProfile());
+
+ // execute the 'init' expression
+ JSONObject message = (JSONObject) input.getValueByField("message");
+ Map<String, String> expressions = profileConfig.getInit();
+ expressions.forEach((var, expr) -> executor.assign(var, expr, message));
+ }
+
+ /**
+ * Update the Profile based on data contained in a new message.
+ * @param input The tuple containing a new message.
+ */
+ private void update(Tuple input) throws IOException {
+ JSONObject message = (JSONObject) input.getValueByField("message");
+
+ // execute each of the 'update' expressions
+ Map<String, String> expressions = profileConfig.getUpdate();
+ expressions.forEach((var, expr) -> executor.assign(var, expr, message));
+ }
+
+ /**
+ * Flush the Profile.
+ *
+ * Executed on a fixed time period when a tick tuple is received. Completes
+ * and emits the ProfileMeasurement. Clears all state in preparation for
+ * the next window period.
+ */
+ private void flush(Tuple tickTuple) throws IOException {
+ LOG.info(String.format("Flushing profile: profile=%s, entity=%s, start=%d",
+ measurement.getProfileName(), measurement.getEntity(), measurement.getStart()));
+
+ // execute the 'result' expression
+ String resultExpr = profileConfig.getResult();
+ Long result = executor.execute(resultExpr, new JSONObject(), Long.class);
--- End diff --
I intended for this to be a Double, not a Long. We expect the profiler to produce a time series, so a large floating point value is what I would expect to be most useful to users.
On the other hand, do I even need knowledge of what type the resulting value is? It seems more user-friendly If I just treat it as an Object, and then allow the HBaseBolt to serialize it to HBase. Then each profile can produce a time series of whatever values they prefer.
The only ugly part is that I'd have to an "if-else instanceof" chain to cast it to the appropriate type in ProfileHBaseMapper.columns(Tuple). I'd have to do this because Java will not be able to resolve Bytes.toBytes(Object).
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75325337
--- Diff: metron-analytics/metron-profiler/src/test/java/org/apache/metron/profiler/integration/ProfilerIntegrationTest.java ---
@@ -0,0 +1,226 @@
+/*
+ *
+ * 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.integration;
+
+import org.adrianwalker.multilinestring.Multiline;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.client.HTableInterface;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.metron.common.Constants;
+import org.apache.metron.common.spout.kafka.SpoutConfig;
+import org.apache.metron.hbase.TableProvider;
+import org.apache.metron.integration.BaseIntegrationTest;
+import org.apache.metron.integration.ComponentRunner;
+import org.apache.metron.integration.components.FluxTopologyComponent;
+import org.apache.metron.integration.components.KafkaWithZKComponent;
+import org.apache.metron.profiler.bolt.ProfileHBaseMapper;
+import org.apache.metron.test.mock.MockHTable;
+import org.junit.After;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static com.google.code.tempusfugit.temporal.Duration.seconds;
+import static com.google.code.tempusfugit.temporal.Timeout.timeout;
+import static com.google.code.tempusfugit.temporal.WaitFor.waitOrTimeout;
+
+/**
+ * An integration test of the Profiler topology.
+ */
+public class ProfilerIntegrationTest extends BaseIntegrationTest {
+
+ private static final String TEST_RESOURCES = "../../metron-analytics/metron-profiler/src/test";
+ private static final String FLUX_PATH = "../metron-profiler/src/main/flux/profiler/remote.yaml";
+
+ /**
+ * {
+ * "ip_src_addr": "10.0.0.1",
+ * "protocol": "HTTPS",
+ * "length": 10,
+ * "bytes_in": 234
+ * }
+ */
+ @Multiline
+ private String message1;
+
+ /**
+ * {
+ * "ip_src_addr": "10.0.0.2",
+ * "protocol": "HTTP",
+ * "length": 20,
+ * "bytes_in": 390
+ * }
+ */
+ @Multiline
+ private String message2;
+
+ /**
+ * {
+ * "ip_src_addr": "10.0.0.3",
+ * "protocol": "DNS",
+ * "length": 30,
+ * "bytes_in": 560
+ * }
+ */
+ @Multiline
+ private String message3;
+
+ private FluxTopologyComponent fluxComponent;
+ private KafkaWithZKComponent kafkaComponent;
+ private List<byte[]> input;
+ private ComponentRunner runner;
+ private MockHTable profilerTable;
+
+ private static final String tableName = "profiler";
+ private static final String columnFamily = "cfProfile";
+
+ /**
+ * A TableProvider that allows us to mock HBase.
+ */
+ public static class MockTableProvider implements TableProvider, Serializable {
+
+ MockHTable.Provider provider = new MockHTable.Provider();
+
+ @Override
+ public HTableInterface getTable(Configuration config, String tableName) throws IOException {
+ return provider.getTable(config, tableName);
+ }
+ }
+
+ public void setup(String pathToConfig) throws Exception {
+
+ // create input messages for the profiler to consume
+ input = Stream.of(message1, message2, message3)
--- End diff --
Dig. +1!
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75336713
--- Diff: metron-analytics/metron-profiler/src/test/config/zookeeper/readme-example-1/profiler.json ---
@@ -0,0 +1,17 @@
+{
+ "inputTopic": "indexing",
+ "profiles": [
+ {
+ "profile": "example1",
+ "foreach": "ip_src_addr",
+ "onlyif": "protocol == 'HTTP'",
+ "init": {
+ "total_bytes": 0.0
--- End diff --
awesome, thanks
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75355685
--- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/bolt/ProfileSplitterBolt.java ---
@@ -0,0 +1,161 @@
+/*
+ *
+ * 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.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.configuration.profiler.ProfilerConfig;
+import org.apache.metron.profiler.stellar.StellarExecutor;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+
+import static java.lang.String.format;
+
+/**
+ * The bolt responsible for filtering incoming messages and directing
+ * each to the one or more bolts responsible for building a Profile. Each
+ * message may be needed by 0, 1 or even many Profiles.
+ */
+public class ProfileSplitterBolt extends ConfiguredProfilerBolt {
+
+ protected static final Logger LOG = LoggerFactory.getLogger(ProfileSplitterBolt.class);
+
+ private OutputCollector collector;
+
+ /**
+ * JSON parser.
+ */
+ private transient JSONParser parser;
+
+ /**
+ * Executes Stellar code.
+ */
+ private StellarExecutor executor;
+
+ /**
+ * @param zookeeperUrl The Zookeeper URL that contains the configuration for this bolt.
+ */
+ public ProfileSplitterBolt(String zookeeperUrl) {
+ super(zookeeperUrl);
+ }
+
+ @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 execute(Tuple input) {
+ try {
+ doExecute(input);
+
+ } catch (IllegalArgumentException | ParseException | UnsupportedEncodingException e) {
+ LOG.error(format("Unexpected failure: message='%s', tuple='%s'", e.getMessage(), input), e);
+ collector.reportError(e);
+
+ } finally {
+ collector.ack(input);
+ }
+ }
+
+ private void doExecute(Tuple input) throws ParseException, UnsupportedEncodingException {
+
+ // retrieve the input message
+ byte[] data = input.getBinary(0);
+ JSONObject message = (JSONObject) parser.parse(new String(data, "UTF8"));
+
+ // ensure there is a valid profiler configuration
+ ProfilerConfig config = getProfilerConfig();
+ if(config == null) {
+ throw new IllegalArgumentException("Fatal: Unable to find valid profiler definition");
+ }
+
+ // apply the message to each of the profile definitions
+ for (ProfileConfig profile: config.getProfiles()) {
+ applyProfile(profile, input, message);
+ }
+ }
+
+ /**
+ * Applies a message to a Profile definition.
+ * @param profile The profile definition.
+ * @param input The input tuple that delivered the message.
+ * @param message The message that may be needed by the profile.
+ */
+ private void applyProfile(ProfileConfig profile, Tuple input, JSONObject message) throws ParseException, UnsupportedEncodingException {
+
+ // is this message needed by this profile?
+ String onlyIf = profile.getOnlyif();
+ if (executor.execute(onlyIf, message, Boolean.class)) {
+
+ // what is the name of the entity in this message?
+ String entity = executor.execute(profile.getForeach(), message, String.class);
+
+ // emit a message for the bolt responsible for building this profile
+ collector.emit(input, new Values(entity, profile, copyMessage(input)));
--- End diff --
No. I don't think I need a deep copy there. I started with that early on in the build, but it is not needed now.
---
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.
---
[GitHub] incubator-metron issue #208: METRON-309 Create a normalcy profiler
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:
https://github.com/apache/incubator-metron/pull/208
+1, great job!
---
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.
---
[GitHub] incubator-metron issue #208: METRON-309 Create a normalcy profiler
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:
https://github.com/apache/incubator-metron/pull/208
So I think this looks good, the one thing that I'd like to see that I didn't is a set of classes around reading the data from the HBase table populated by the profiler. Things like reading the output of a profile for a given time (or if not specified, then the latest).
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75318026
--- 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 --
Should we be acking here?
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75324397
--- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/stellar/DefaultStellarExecutor.java ---
@@ -0,0 +1,116 @@
+/*
+ *
+ * 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.stellar;
+
+import org.apache.metron.common.dsl.MapVariableResolver;
+import org.apache.metron.common.dsl.ParseException;
+import org.apache.metron.common.dsl.VariableResolver;
+import org.apache.metron.common.stellar.StellarPredicateProcessor;
+import org.apache.metron.common.stellar.StellarProcessor;
+import org.json.simple.JSONObject;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * The default implementation of a StellarExecutor.
+ */
+public class DefaultStellarExecutor implements StellarExecutor, Serializable {
+
+ /**
+ * The current state of the Stellar execution environment.
+ */
+ private Map<String, Object> state;
+
+ public DefaultStellarExecutor() {
+ clearState();
+ }
+
+ /**
+ * @param initialState Initial state loaded into the execution environment.
+ */
+ public DefaultStellarExecutor(Map<String, Object> initialState) {
+ this.state = new HashMap<>(initialState);
+ }
+
+ @Override
+ public Map<String, Object> getState() {
+ return new HashMap<>(state);
+ }
+
+ /**
+ * Execute an expression and assign the result to a variable.
+ *
+ * @param variable The variable name to assign to.
+ * @param expression The expression to execute.
+ * @param message The message that provides additional context for the expression.
+ */
+ @Override
+ public void assign(String variable, String expression, JSONObject message) {
+ Object result = execute(expression, message);
+ state.put(variable, result);
+ }
+
+ /**
+ * Execute a Stellar expression and returns the result.
+ *
+ * @param expr The expression to execute.
+ * @param message The message that is accessible when Stellar is executed.
+ * @param clazz The expected class of the expression's result.
+ * @param <T> The expected class of the expression's result.
+ */
+ @Override
+ public <T> T execute(String expr, JSONObject message, Class<T> clazz) {
+ Object result = execute(expr, message);
+
+ // ensure the result type is as expected
+ if (clazz.isAssignableFrom(result.getClass())) {
+ return (T) result;
+
+ } else {
+ throw new RuntimeException(String.format("Unexpected type: expected=%s, actual=%s, expression=%s",
--- End diff --
If you wanted to be extra adaptable, you might consider using the ConversionUtils class to try to convert to the target type if it's not assignable and *then* (if null is returned) throw an exception. Just a thought.
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75381356
--- Diff: metron-analytics/metron-profiler/src/test/config/zookeeper/readme-example-1/profiler.json ---
@@ -0,0 +1,17 @@
+{
+ "inputTopic": "indexing",
+ "profiles": [
+ {
+ "profile": "example1",
+ "foreach": "ip_src_addr",
+ "onlyif": "protocol == 'HTTP'",
+ "init": {
+ "total_bytes": 0.0
--- End diff --
I also added a better description of each of the fields in the README. That should help with this type of question.
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by nickwallen <gi...@git.apache.org>.
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.
---
[GitHub] incubator-metron issue #208: METRON-309 Create a normalcy profiler
Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on the issue:
https://github.com/apache/incubator-metron/pull/208
I just added some docs in the README on the topology configuration settings. This includes the salt divisor. Let me know if that makes sense. Its a table so you'll need to view the rendered markdown.
---
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.
---
[GitHub] incubator-metron pull request #208: METRON-309 Create a normalcy profiler
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/208#discussion_r75324767
--- Diff: metron-analytics/metron-profiler/src/test/config/zookeeper/readme-example-1/profiler.json ---
@@ -0,0 +1,17 @@
+{
+ "inputTopic": "indexing",
+ "profiles": [
+ {
+ "profile": "example1",
+ "foreach": "ip_src_addr",
+ "onlyif": "protocol == 'HTTP'",
+ "init": {
+ "total_bytes": 0.0
--- End diff --
Can init take stellar statements? There will be situations where we'll want to init via stellar (e.g. bloom filter with specific parameters). If not, we should make it accept it.
---
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.
---