You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metron.apache.org by ni...@apache.org on 2016/11/03 15:15:06 UTC
incubator-metron git commit: METRON-529 Allow Configurable Periods
for Profiler Client (nickwallen) closes apache/incubator-metron#334
Repository: incubator-metron
Updated Branches:
refs/heads/master 1cf6cc943 -> 05d29e7cb
METRON-529 Allow Configurable Periods for Profiler Client (nickwallen) closes apache/incubator-metron#334
Project: http://git-wip-us.apache.org/repos/asf/incubator-metron/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-metron/commit/05d29e7c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-metron/tree/05d29e7c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-metron/diff/05d29e7c
Branch: refs/heads/master
Commit: 05d29e7cb5b1958e79cbfa6d576ab48b40aa508f
Parents: 1cf6cc9
Author: nickwallen <ni...@nickallen.org>
Authored: Thu Nov 3 11:14:06 2016 -0400
Committer: Nick Allen <ni...@nickallen.org>
Committed: Thu Nov 3 11:14:06 2016 -0400
----------------------------------------------------------------------
.../metron-profiler-client/README.md | 15 +++--
.../profiler/client/stellar/GetProfile.java | 71 ++++++++++++++++----
.../metron/profiler/client/GetProfileTest.java | 17 ++---
.../metron/profiler/client/ProfileWriter.java | 25 +++++++
.../profiler/hbase/SaltyRowKeyBuilder.java | 3 +-
metron-analytics/metron-profiler/README.md | 4 +-
.../src/main/config/profiler.properties | 1 -
.../src/main/config/zookeeper/global.json | 9 ++-
8 files changed, 114 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05d29e7c/metron-analytics/metron-profiler-client/README.md
----------------------------------------------------------------------
diff --git a/metron-analytics/metron-profiler-client/README.md b/metron-analytics/metron-profiler-client/README.md
index ff2ba0c..dc4adb0 100644
--- a/metron-analytics/metron-profiler-client/README.md
+++ b/metron-analytics/metron-profiler-client/README.md
@@ -41,13 +41,20 @@ Retrieve all values of 'snort-alerts' from '10.0.0.1' that occurred on 'weekdays
PROFILE_GET('snort-alerts', '10.0.0.1', 1, 'MONTHS', 'weekdays')
```
-### Period Duration
+### Configuration
-*WARNING*
+By default, the Profiler creates Profiles with a period duration of 15 minutes. This means that data is accumulated, summarized and flushed every 15 minutes. The Client API must also have knowledge of this duration to correctly retrieve the profile data. If the client API is expecting 15 minute periods, it will not be able to read data generated by a Profiler that has been configured with a 1 hour period.
-By default, the Profiler creates Profiles with a period duration of 15 minutes. This means that data is accumulated, summarized and flushed every 15 minutes. The Client API must also have knowledge of this duration to correctly retrieve the profile data. If the client API is expected 15 minute periods, it will not be able to read data generated by a Profiler that has been configured with a 1 hour period.
+The period duration can be configured in the Profiler by altering the Profiler topology's static properties file (`$METRON/config/profiler.properties`). The Stellar Client API can be configured by setting the following properties in Metron's global configuration.
-The period duration can be configured in the Profiler by altering the Profiler topology's static properties file. The Stellar Client API currently provides no means to configure the period duration and defaults also to 15 minutes. This means that the Stellar Client API can only read profiles with a period duration of 15 minutes. This is a known limitation that has not yet been addressed.
+| Key | Description | Required | Default |
+| ------------------------------------- | -------- | -------- | -------- |
+| profiler.client.period.duration | The duration of each profile period. This value should be defined along with `profiler.client.period.duration.units`. | Optional | 15 |
+| profiler.client.period.duration.units | The units used to specify the profile period duration. This value should be defined along with `profiler.client.period.duration`. | Optional | MINUTES |
+| profiler.client.hbase.table | The name of the HBase table used to store profile data. | Optional | profiler |
+| profiler.client.hbase.column.family | The name of the HBase column family used to store profile data. | Optional | P |
+| profiler.client.salt.divisor | The salt divisor used to store profile data. | Optional | 1000 |
+| hbase.provider.impl | The name of the HBaseTableProvider implementation class. | Optional | |
## Getting Started
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05d29e7c/metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/GetProfile.java
----------------------------------------------------------------------
diff --git a/metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/GetProfile.java b/metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/GetProfile.java
index f4b3a8d..2f13967 100644
--- a/metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/GetProfile.java
+++ b/metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/GetProfile.java
@@ -36,6 +36,8 @@ import org.apache.metron.profiler.hbase.ColumnBuilder;
import org.apache.metron.profiler.hbase.RowKeyBuilder;
import org.apache.metron.profiler.hbase.SaltyRowKeyBuilder;
import org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
@@ -82,19 +84,53 @@ import static org.apache.metron.common.dsl.Context.Capabilities.GLOBAL_CONFIG;
public class GetProfile implements StellarFunction {
/**
- * A global property that defines the name of the HBase table storing profile definitions.
+ * A global property that defines the name of the HBase table used to store profile data.
*/
- public static final String PROFILER_HBASE_TABLE = "profiler.hbase.table";
+ public static final String PROFILER_HBASE_TABLE = "profiler.client.hbase.table";
/**
* A global property that defines the name of the column family used to store profile data.
*/
- public static final String PROFILER_COLUMN_FAMILY = "profiler.column.family";
+ public static final String PROFILER_COLUMN_FAMILY = "profiler.client.hbase.column.family";
/**
* A global property that defines the name of the HBaseTableProvider implementation class.
*/
- public static final String PROFILER_HBASE_TABLE_PROVIDER = "profiler.hbase.table.provider";
+ public static final String PROFILER_HBASE_TABLE_PROVIDER = "hbase.provider.impl";
+
+ /**
+ * A global property that defines the duration of each profile period. This value
+ * should be defined along with 'profiler.client.period.duration.units'.
+ */
+ public static final String PROFILER_PERIOD = "profiler.client.period.duration";
+
+ /**
+ * A global property that defines the units of the profile period duration. This value
+ * should be defined along with 'profiler.client.period.duration'.
+ */
+ public static final String PROFILER_PERIOD_UNITS = "profiler.client.period.duration.units";
+
+ /**
+ * A global property that defines the salt divisor used to store profile data.
+ */
+ public static final String PROFILER_SALT_DIVISOR = "profiler.client.salt.divisor";
+
+ /**
+ * The default Profile period duration should none be defined in the global properties.
+ */
+ public static final String PROFILER_PERIOD_DEFAULT = "15";
+
+ /**
+ * The default units of the Profile period should none be defined in the global properties.
+ */
+ public static final String PROFILER_PERIOD_UNITS_DEFAULT = "MINUTES";
+
+ /**
+ * The default salt divisor should none be defined in the global properties.
+ */
+ public static final String PROFILER_SALT_DIVISOR_DEFAULT = "1000";
+
+ private static final Logger LOG = LoggerFactory.getLogger(GetProfile.class);
/**
* A client that can retrieve profile values.
@@ -113,8 +149,8 @@ public class GetProfile implements StellarFunction {
Map<String, Object> global = (Map<String, Object>) context.getCapability(GLOBAL_CONFIG).get();
// create the profiler client
- ColumnBuilder columnBuilder = getColumnBuilder(global);
RowKeyBuilder rowKeyBuilder = getRowKeyBuilder(global);
+ ColumnBuilder columnBuilder = getColumnBuilder(global);
HTableInterface table = getTable(global);
client = new HBaseProfilerClient(table, rowKeyBuilder, columnBuilder);
}
@@ -226,14 +262,23 @@ public class GetProfile implements StellarFunction {
* @param global The global configuration.
*/
private RowKeyBuilder getRowKeyBuilder(Map<String, Object> global) {
- /*
- * WARNING: the row key builder is not currently configurable. by invoking
- * the default constructor below, this defaults to generating keys using a
- * period duration of 15 minutes. this function will NOT be able to read
- * profiles created by a profiler running with any other period duration, but
- * 15 minutes.
- */
- return new SaltyRowKeyBuilder();
+
+ // how long is the profile period?
+ String configuredDuration = (String) global.getOrDefault(PROFILER_PERIOD, PROFILER_PERIOD_DEFAULT);
+ long duration = Long.parseLong(configuredDuration);
+ LOG.debug("profiler client: {}={}", PROFILER_PERIOD, duration);
+
+ // which units are used to define the profile period?
+ String configuredUnits = (String) global.getOrDefault(PROFILER_PERIOD_UNITS, PROFILER_PERIOD_UNITS_DEFAULT);
+ TimeUnit units = TimeUnit.valueOf(configuredUnits);
+ LOG.debug("profiler client: {}={}", PROFILER_PERIOD_UNITS, units);
+
+ // what is the salt divisor?
+ String configuredSaltDivisor = (String) global.getOrDefault(PROFILER_SALT_DIVISOR, PROFILER_SALT_DIVISOR_DEFAULT);
+ int saltDivisor = Integer.parseInt(configuredSaltDivisor);
+ LOG.debug("profiler client: {}={}", PROFILER_SALT_DIVISOR, saltDivisor);
+
+ return new SaltyRowKeyBuilder(saltDivisor, duration, units);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05d29e7c/metron-analytics/metron-profiler-client/src/test/java/org/apache/metron/profiler/client/GetProfileTest.java
----------------------------------------------------------------------
diff --git a/metron-analytics/metron-profiler-client/src/test/java/org/apache/metron/profiler/client/GetProfileTest.java b/metron-analytics/metron-profiler-client/src/test/java/org/apache/metron/profiler/client/GetProfileTest.java
index dbecca0..fd68c7f 100644
--- a/metron-analytics/metron-profiler-client/src/test/java/org/apache/metron/profiler/client/GetProfileTest.java
+++ b/metron-analytics/metron-profiler-client/src/test/java/org/apache/metron/profiler/client/GetProfileTest.java
@@ -50,12 +50,18 @@ import java.util.concurrent.TimeUnit;
import static org.apache.metron.profiler.client.stellar.GetProfile.PROFILER_COLUMN_FAMILY;
import static org.apache.metron.profiler.client.stellar.GetProfile.PROFILER_HBASE_TABLE;
import static org.apache.metron.profiler.client.stellar.GetProfile.PROFILER_HBASE_TABLE_PROVIDER;
+import static org.apache.metron.profiler.client.stellar.GetProfile.PROFILER_PERIOD;
+import static org.apache.metron.profiler.client.stellar.GetProfile.PROFILER_PERIOD_UNITS;
+import static org.apache.metron.profiler.client.stellar.GetProfile.PROFILER_SALT_DIVISOR;
/**
* Tests the GetProfile class.
*/
public class GetProfileTest {
+ private static final long periodDuration = 15;
+ private static final TimeUnit periodUnits = TimeUnit.MINUTES;
+ private static final int saltDivisor = 1000;
private static final String tableName = "profiler";
private static final String columnFamily = "P";
private StellarExecutor executor;
@@ -94,6 +100,9 @@ public class GetProfileTest {
put(PROFILER_HBASE_TABLE, tableName);
put(PROFILER_COLUMN_FAMILY, columnFamily);
put(PROFILER_HBASE_TABLE_PROVIDER, MockTableProvider.class.getName());
+ put(PROFILER_PERIOD, Long.toString(periodDuration));
+ put(PROFILER_PERIOD_UNITS, periodUnits.toString());
+ put(PROFILER_SALT_DIVISOR, Integer.toString(saltDivisor));
}};
// create the necessary context
@@ -114,8 +123,6 @@ public class GetProfileTest {
*/
@Test
public void testWithNoGroups() {
- final long periodDuration = 15;
- final TimeUnit periodUnits = TimeUnit.MINUTES;
final int periodsPerHour = 4;
final int expectedValue = 2302;
final int hours = 2;
@@ -140,8 +147,6 @@ public class GetProfileTest {
*/
@Test
public void testWithOneGroup() {
- final long periodDuration = 15;
- final TimeUnit periodUnits = TimeUnit.MINUTES;
final int periodsPerHour = 4;
final int expectedValue = 2302;
final int hours = 2;
@@ -169,8 +174,6 @@ public class GetProfileTest {
*/
@Test
public void testWithTwoGroups() {
- final long periodDuration = 15;
- final TimeUnit periodUnits = TimeUnit.MINUTES;
final int periodsPerHour = 4;
final int expectedValue = 2302;
final int hours = 2;
@@ -217,8 +220,6 @@ public class GetProfileTest {
*/
@Test
public void testOutsideTimeHorizon() {
- final long periodDuration = 15;
- final TimeUnit periodUnits = TimeUnit.MINUTES;
final int expectedValue = 2302;
final int hours = 2;
final long startTime = System.currentTimeMillis() - TimeUnit.HOURS.toMillis(hours);
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05d29e7c/metron-analytics/metron-profiler-client/src/test/java/org/apache/metron/profiler/client/ProfileWriter.java
----------------------------------------------------------------------
diff --git a/metron-analytics/metron-profiler-client/src/test/java/org/apache/metron/profiler/client/ProfileWriter.java b/metron-analytics/metron-profiler-client/src/test/java/org/apache/metron/profiler/client/ProfileWriter.java
index 0ad2f44..503e118 100644
--- a/metron-analytics/metron-profiler-client/src/test/java/org/apache/metron/profiler/client/ProfileWriter.java
+++ b/metron-analytics/metron-profiler-client/src/test/java/org/apache/metron/profiler/client/ProfileWriter.java
@@ -20,16 +20,23 @@
package org.apache.metron.profiler.client;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.HTableInterface;
+import org.apache.metron.hbase.HTableProvider;
import org.apache.metron.hbase.bolt.mapper.ColumnList;
import org.apache.metron.hbase.client.HBaseClient;
import org.apache.metron.profiler.ProfileMeasurement;
import org.apache.metron.profiler.ProfilePeriod;
import org.apache.metron.profiler.hbase.ColumnBuilder;
import org.apache.metron.profiler.hbase.RowKeyBuilder;
+import org.apache.metron.profiler.hbase.SaltyRowKeyBuilder;
+import org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder;
+import java.util.Collections;
import java.util.List;
+import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
@@ -95,4 +102,22 @@ public class ProfileWriter {
hbaseClient.mutate();
}
+ public static void main(String[] args) throws Exception {
+ RowKeyBuilder rowKeyBuilder = new SaltyRowKeyBuilder();
+ ColumnBuilder columnBuilder = new ValueOnlyColumnBuilder();
+
+ Configuration config = HBaseConfiguration.create();
+ config.set("hbase.master.hostname", "node1");
+ config.set("hbase.regionserver.hostname", "node1");
+ config.set("hbase.zookeeper.quorum", "node1");
+
+ HTableProvider provider = new HTableProvider();
+ HTableInterface table = provider.getTable(config, "profiler");
+
+ long when = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(2);
+ ProfileMeasurement measure = new ProfileMeasurement("profile1", "192.168.66.121", when, 15, TimeUnit.MINUTES);
+
+ ProfileWriter writer = new ProfileWriter(rowKeyBuilder, columnBuilder, table);
+ writer.write(measure, 2 * 24 * 4, Collections.emptyList(), val -> new Random().nextInt(10));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05d29e7c/metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/hbase/SaltyRowKeyBuilder.java
----------------------------------------------------------------------
diff --git a/metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/hbase/SaltyRowKeyBuilder.java b/metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/hbase/SaltyRowKeyBuilder.java
index ee54a1a..f7788bd 100644
--- a/metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/hbase/SaltyRowKeyBuilder.java
+++ b/metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/hbase/SaltyRowKeyBuilder.java
@@ -178,7 +178,8 @@ public class SaltyRowKeyBuilder implements RowKeyBuilder {
* @param period The ProfilePeriod in which the ProfileMeasurement was taken.
*/
private static byte[] timeKey(ProfilePeriod period) {
- return Bytes.toBytes(period.getPeriod());
+ long thePeriod = period.getPeriod();
+ return Bytes.toBytes(thePeriod);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05d29e7c/metron-analytics/metron-profiler/README.md
----------------------------------------------------------------------
diff --git a/metron-analytics/metron-profiler/README.md b/metron-analytics/metron-profiler/README.md
index 5659090..f1add33 100644
--- a/metron-analytics/metron-profiler/README.md
+++ b/metron-analytics/metron-profiler/README.md
@@ -219,9 +219,11 @@ The Profiler topology also accepts the following configuration settings.
| profiler.workers | The number of worker processes to create for the topology. |
| profiler.executors | The number of executors to spawn per component. |
| profiler.input.topic | The name of the Kafka topic from which to consume data. |
-| profiler.flush.interval.seconds | The duration of a profile's sliding window before it is flushed. |
+| profiler.period.duration | The duration of each profile period. This value should be defined along with `profiler.period.duration.units`. |
+| profiler.period.duration.units | The units used to specify the profile period duration. This value should be defined along with `profiler.period.duration`. |
| profiler.hbase.salt.divisor | 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. |
| profiler.hbase.table | The name of the HBase table that profiles are written to. |
+| profiler.hbase.column.family | The column family used to store profiles. |
| profiler.hbase.batch | The number of puts that are written in a single batch. |
| profiler.hbase.flush.interval.seconds | The maximum number of seconds between batch writes to HBase. |
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05d29e7c/metron-analytics/metron-profiler/src/main/config/profiler.properties
----------------------------------------------------------------------
diff --git a/metron-analytics/metron-profiler/src/main/config/profiler.properties b/metron-analytics/metron-profiler/src/main/config/profiler.properties
index d2b8544..a3448aa 100644
--- a/metron-analytics/metron-profiler/src/main/config/profiler.properties
+++ b/metron-analytics/metron-profiler/src/main/config/profiler.properties
@@ -31,7 +31,6 @@ profiler.hbase.column.family=P
profiler.hbase.batch=10
profiler.hbase.flush.interval.seconds=30
-
##### Kafka #####
kafka.zk=node1:2181
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05d29e7c/metron-platform/metron-integration-test/src/main/config/zookeeper/global.json
----------------------------------------------------------------------
diff --git a/metron-platform/metron-integration-test/src/main/config/zookeeper/global.json b/metron-platform/metron-integration-test/src/main/config/zookeeper/global.json
index 3f2ee58..5ac0579 100644
--- a/metron-platform/metron-integration-test/src/main/config/zookeeper/global.json
+++ b/metron-platform/metron-integration-test/src/main/config/zookeeper/global.json
@@ -16,7 +16,10 @@
}
],
- "profiler.hbase.table": "profiler",
- "profiler.column.family": "P",
- "profiler.hbase.table.provider": "org.apache.metron.hbase.HTableProvider"
+ "profiler.client.period.duration": "15",
+ "profiler.client.period.duration.units": "MINUTES",
+ "profiler.client.hbase.table": "profiler",
+ "profiler.client.hbase.column.family": "P",
+ "profiler.client.salt.divisor": "1000",
+ "hbase.provider.impl": "org.apache.metron.hbase.HTableProvider"
}
\ No newline at end of file