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/30 00:59:09 UTC

[GitHub] incubator-metron pull request #236: METRON-389 Create Java API to Read Profi...

GitHub user nickwallen opened a pull request:

    https://github.com/apache/incubator-metron/pull/236

    METRON-389 Create Java API to Read Profile Data During Model Scoring

    [METRON-389](https://issues.apache.org/jira/browse/METRON-389)
    
    ### Changes
    * Created a Java API for reading profile data written by the Profiler.  This is contained within a new project `metron-analytics/metron-profiler-client`.
    * Altered the Profiler to use deterministic row keys so that multiple Gets can fetch the data.  This should scale much better at high volumes.
    
    ### Points of Interest
    * `ProfileMeasurement` - Represents a single data point within a Profile.  A Profile is effectively a time series.  To this end a Profile is composed of many ProfileMeasurement values which in aggregate form a time series.  
    * `ProfilePeriod` - The Profiler captures one `ProfileMeasurement` each `ProfilePeriod`.  A `ProfilePeriod` will occur at fixed, deterministic points in time.  This allows for efficient retrieval of profile data.
    * `RowKeyBuilder` - Builds row keys that can be used to read or write profile data to HBase.
    * `ColumnBuilder` - Defines the columns of data stored with a profile measurement.
    * `ProfileHBaseMapper` - Defines for the `HBaseBolt` how profile measurements are stored in HBase.  This class leverages a `RowKeyBuilder` and `ColumnBuilder`.
    
    ### Testing
    Spin up a Metron install and write some Profile data to HBase.  Read the profile data using `metron-profiler-client`.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/nickwallen/incubator-metron METRON-389-FINAL

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-metron/pull/236.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 #236
    
----
commit e2bd987f1df94174ec60f33c30efa09a0a3c4ace
Author: Nick Allen <ni...@nickallen.org>
Date:   2016-08-23T17:03:15Z

    METRON-389 Create Java API to Read Profile Data During Model Scoring

----


---
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 #236: METRON-389 Create Java API to Read Profi...

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/236#discussion_r78371167
  
    --- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/hbase/SaltyRowKeyBuilder.java ---
    @@ -0,0 +1,211 @@
    +/*
    + *
    + *  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.hbase;
    +
    +import org.apache.hadoop.hbase.util.Bytes;
    +import org.apache.metron.profiler.ProfileMeasurement;
    +import org.apache.metron.profiler.ProfilePeriod;
    +
    +import java.nio.ByteBuffer;
    +import java.security.MessageDigest;
    +import java.security.NoSuchAlgorithmException;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.concurrent.TimeUnit;
    +
    +/**
    + * A RowKeyBuilder that uses a salt to prevent hot-spotting.
    + *
    + * Responsible for building the row keys used to store profile data in HBase.  The row key is composed of the following
    + * fields in the given order.
    + * <ul>
    + * <li>salt - A salt that helps prevent hot-spotting.
    + * <li>profile - The name of the profile.
    + * <li>entity - The name of the entity being profiled.
    + * <li>group(s) - The group(s) used to sort the data in HBase. For example, a group may distinguish between weekends and weekdays.
    + * <li>year - The year based on UTC.
    + * <li>day of year - The current day within the year based on UTC; [1, 366]
    + * <li>hour - The hour within the day based on UTC; [0, 23]
    + * </ul>period - The period within the hour.  The number of periods per hour can be defined by the user; defaults to 4.
    + */
    +public class SaltyRowKeyBuilder implements RowKeyBuilder {
    +
    +  /**
    +   * A salt can be prepended to the row key to help prevent hot-spotting.  The salt
    +   * divisor is used to generate the salt.  The salt divisor should be roughly equal
    +   * to the number of nodes in the Hbase cluster.
    +   */
    +  private int saltDivisor;
    +
    +  /**
    +   * An hour is divided into multiple periods.  This defines how many periods
    +   * will exist within each given hour.
    +   */
    +  private int periodsPerHour;
    +
    +  public SaltyRowKeyBuilder() {
    +    this.saltDivisor = 1000;
    +    this.periodsPerHour = 4;
    +  }
    +
    +  public SaltyRowKeyBuilder(int saltDivisor, int periodsPerHour) {
    +    this.saltDivisor = saltDivisor;
    +    this.periodsPerHour = periodsPerHour;
    +  }
    +
    +  /**
    +   * Builds a list of row keys necessary to retrieve profile measurements over
    +   * a time horizon.
    +   *
    +   * @param profile The name of the profile.
    +   * @param entity The name of the entity.
    +   * @param groups The group(s) used to sort the profile data.
    +   * @param durationAgo How long ago?
    +   * @param unit The time units of how long ago.
    +   * @return All of the row keys necessary to retrieve the profile measurements.
    +   */
    +  @Override
    +  public List<byte[]> rowKeys(String profile, String entity, List<Object> groups, long durationAgo, TimeUnit unit) {
    --- End diff --
    
    Just because it matches the `ProfilerClient` interface.  Could easily be changed to start/end.  What are you thinking the advantages of doing so are?  Easier to test?


---
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 #236: METRON-389 Create Java API to Read Profile Data...

Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on the issue:

    https://github.com/apache/incubator-metron/pull/236
  
    Created METRON-412 and METRON-413 to track those changes.  Will merge once the final CI build completes.


---
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 #236: METRON-389 Create Java API to Read Profi...

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/236#discussion_r78373523
  
    --- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/hbase/Serializer.java ---
    @@ -0,0 +1,92 @@
    +/*
    + *
    + *  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.hbase;
    +
    +import org.apache.hadoop.hbase.util.Bytes;
    +
    +/**
    + * Provides basic functionality to serialize and deserialize the allowed
    + * value types for a ProfileMeasurement.
    + */
    +public class Serializer {
    +
    +  private Serializer() {
    +    // do not instantiate
    +  }
    +
    +  /**
    +   * Serialize a profile measurement's value.
    +   *
    +   * The value produced by a Profile definition can be any numeric data type.  The data
    +   * type depends on how the profile is defined by the user.  The user should be able to
    +   * choose the data type that is most suitable for their use case.
    +   *
    +   * @param value The value to serialize.
    +   */
    +  public static byte[] toBytes(Object value) {
    --- End diff --
    
    Yes, I like that.  I went down this path before, but ran into some unrelated issues and ended up unwinding the change.  There are at least 4 touch points that would change based on this; all good changes.
    
    Wondering if I should just submit this change as a separate PR to make my life easier with the other dependent changes I have in the pipeline.  Looking at the code now  to see how painful that might be.


---
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 #236: METRON-389 Create Java API to Read Profi...

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/236#discussion_r78375578
  
    --- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/hbase/Serializer.java ---
    @@ -0,0 +1,92 @@
    +/*
    + *
    + *  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.hbase;
    +
    +import org.apache.hadoop.hbase.util.Bytes;
    +
    +/**
    + * Provides basic functionality to serialize and deserialize the allowed
    + * value types for a ProfileMeasurement.
    + */
    +public class Serializer {
    +
    +  private Serializer() {
    +    // do not instantiate
    +  }
    +
    +  /**
    +   * Serialize a profile measurement's value.
    +   *
    +   * The value produced by a Profile definition can be any numeric data type.  The data
    +   * type depends on how the profile is defined by the user.  The user should be able to
    +   * choose the data type that is most suitable for their use case.
    +   *
    +   * @param value The value to serialize.
    +   */
    +  public static byte[] toBytes(Object value) {
    --- End diff --
    
    Yep, the suggested change looks good.  Makes the code more clear in a few places too.  I'll do a follow-on PR.  Created [METRON-412](https://issues.apache.org/jira/browse/METRON-412) to track this.


---
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 #236: METRON-389 Create Java API to Read Profi...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-metron/pull/236


---
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 #236: METRON-389 Create Java API to Read Profile Data...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:

    https://github.com/apache/incubator-metron/pull/236
  
    Ok, I think I'm +1 on this pending the two JIRAs mentioned from the review:
    * Adjust `ProfilerClient` to add a method that takes a start/end time method. 
    * Change the `Serializer.toBytes(Object)` to `Serializer.toBytes(Number)`


---
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 #236: METRON-389 Create Java API to Read Profi...

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/236#discussion_r78370176
  
    --- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/bolt/ProfileBuilderBolt.java ---
    @@ -194,8 +194,8 @@ private void init(Tuple input) {
           expressions.forEach((var, expr) -> executor.assign(var, expr, message));
     
         } catch(ParseException e) {
    -      String msg = format("Bad 'init' expression: %s, profile=%s, entity=%s, start=%d",
    -              e.getMessage(), measurement.getProfileName(), measurement.getEntity(), measurement.getStart());
    +      String msg = format("Bad 'init' expression: %s, profile=%s, entity=%s",
    +              e.getMessage(), measurement.getProfileName(), measurement.getEntity());
    --- End diff --
    
    Ok, retracted


---
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 #236: METRON-389 Create Java API to Read Profi...

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/236#discussion_r78368076
  
    --- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/bolt/ProfileBuilderBolt.java ---
    @@ -194,8 +194,8 @@ private void init(Tuple input) {
           expressions.forEach((var, expr) -> executor.assign(var, expr, message));
     
         } catch(ParseException e) {
    -      String msg = format("Bad 'init' expression: %s, profile=%s, entity=%s, start=%d",
    -              e.getMessage(), measurement.getProfileName(), measurement.getEntity(), measurement.getStart());
    +      String msg = format("Bad 'init' expression: %s, profile=%s, entity=%s",
    +              e.getMessage(), measurement.getProfileName(), measurement.getEntity());
    --- End diff --
    
    Can we LOG.error these 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 #236: METRON-389 Create Java API to Read Profi...

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/236#discussion_r78374790
  
    --- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/hbase/SaltyRowKeyBuilder.java ---
    @@ -0,0 +1,211 @@
    +/*
    + *
    + *  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.hbase;
    +
    +import org.apache.hadoop.hbase.util.Bytes;
    +import org.apache.metron.profiler.ProfileMeasurement;
    +import org.apache.metron.profiler.ProfilePeriod;
    +
    +import java.nio.ByteBuffer;
    +import java.security.MessageDigest;
    +import java.security.NoSuchAlgorithmException;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.concurrent.TimeUnit;
    +
    +/**
    + * A RowKeyBuilder that uses a salt to prevent hot-spotting.
    + *
    + * Responsible for building the row keys used to store profile data in HBase.  The row key is composed of the following
    + * fields in the given order.
    + * <ul>
    + * <li>salt - A salt that helps prevent hot-spotting.
    + * <li>profile - The name of the profile.
    + * <li>entity - The name of the entity being profiled.
    + * <li>group(s) - The group(s) used to sort the data in HBase. For example, a group may distinguish between weekends and weekdays.
    + * <li>year - The year based on UTC.
    + * <li>day of year - The current day within the year based on UTC; [1, 366]
    + * <li>hour - The hour within the day based on UTC; [0, 23]
    + * </ul>period - The period within the hour.  The number of periods per hour can be defined by the user; defaults to 4.
    + */
    +public class SaltyRowKeyBuilder implements RowKeyBuilder {
    +
    +  /**
    +   * A salt can be prepended to the row key to help prevent hot-spotting.  The salt
    +   * divisor is used to generate the salt.  The salt divisor should be roughly equal
    +   * to the number of nodes in the Hbase cluster.
    +   */
    +  private int saltDivisor;
    +
    +  /**
    +   * An hour is divided into multiple periods.  This defines how many periods
    +   * will exist within each given hour.
    +   */
    +  private int periodsPerHour;
    +
    +  public SaltyRowKeyBuilder() {
    +    this.saltDivisor = 1000;
    +    this.periodsPerHour = 4;
    +  }
    +
    +  public SaltyRowKeyBuilder(int saltDivisor, int periodsPerHour) {
    +    this.saltDivisor = saltDivisor;
    +    this.periodsPerHour = periodsPerHour;
    +  }
    +
    +  /**
    +   * Builds a list of row keys necessary to retrieve profile measurements over
    +   * a time horizon.
    +   *
    +   * @param profile The name of the profile.
    +   * @param entity The name of the entity.
    +   * @param groups The group(s) used to sort the profile data.
    +   * @param durationAgo How long ago?
    +   * @param unit The time units of how long ago.
    +   * @return All of the row keys necessary to retrieve the profile measurements.
    +   */
    +  @Override
    +  public List<byte[]> rowKeys(String profile, String entity, List<Object> groups, long durationAgo, TimeUnit unit) {
    --- End diff --
    
    Then we would also want to change the ProfilerClient interface to let you do this.  I think its a reasonable change.  I'd prefer to do this one as a separate PR as it would definitely impact the PRs in the pipeline.


---
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 #236: METRON-389 Create Java API to Read Profi...

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/236#discussion_r78369359
  
    --- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/hbase/Serializer.java ---
    @@ -0,0 +1,92 @@
    +/*
    + *
    + *  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.hbase;
    +
    +import org.apache.hadoop.hbase.util.Bytes;
    +
    +/**
    + * Provides basic functionality to serialize and deserialize the allowed
    + * value types for a ProfileMeasurement.
    + */
    +public class Serializer {
    +
    +  private Serializer() {
    +    // do not instantiate
    +  }
    +
    +  /**
    +   * Serialize a profile measurement's value.
    +   *
    +   * The value produced by a Profile definition can be any numeric data type.  The data
    +   * type depends on how the profile is defined by the user.  The user should be able to
    +   * choose the data type that is most suitable for their use case.
    +   *
    +   * @param value The value to serialize.
    +   */
    +  public static byte[] toBytes(Object value) {
    --- End diff --
    
    If we are restricting to numeric data, why not have toBytes take a Number argument as opposed to 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 #236: METRON-389 Create Java API to Read Profi...

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/236#discussion_r78371624
  
    --- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/hbase/SaltyRowKeyBuilder.java ---
    @@ -0,0 +1,211 @@
    +/*
    + *
    + *  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.hbase;
    +
    +import org.apache.hadoop.hbase.util.Bytes;
    +import org.apache.metron.profiler.ProfileMeasurement;
    +import org.apache.metron.profiler.ProfilePeriod;
    +
    +import java.nio.ByteBuffer;
    +import java.security.MessageDigest;
    +import java.security.NoSuchAlgorithmException;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.concurrent.TimeUnit;
    +
    +/**
    + * A RowKeyBuilder that uses a salt to prevent hot-spotting.
    + *
    + * Responsible for building the row keys used to store profile data in HBase.  The row key is composed of the following
    + * fields in the given order.
    + * <ul>
    + * <li>salt - A salt that helps prevent hot-spotting.
    + * <li>profile - The name of the profile.
    + * <li>entity - The name of the entity being profiled.
    + * <li>group(s) - The group(s) used to sort the data in HBase. For example, a group may distinguish between weekends and weekdays.
    + * <li>year - The year based on UTC.
    + * <li>day of year - The current day within the year based on UTC; [1, 366]
    + * <li>hour - The hour within the day based on UTC; [0, 23]
    + * </ul>period - The period within the hour.  The number of periods per hour can be defined by the user; defaults to 4.
    + */
    +public class SaltyRowKeyBuilder implements RowKeyBuilder {
    +
    +  /**
    +   * A salt can be prepended to the row key to help prevent hot-spotting.  The salt
    +   * divisor is used to generate the salt.  The salt divisor should be roughly equal
    +   * to the number of nodes in the Hbase cluster.
    +   */
    +  private int saltDivisor;
    +
    +  /**
    +   * An hour is divided into multiple periods.  This defines how many periods
    +   * will exist within each given hour.
    +   */
    +  private int periodsPerHour;
    +
    +  public SaltyRowKeyBuilder() {
    +    this.saltDivisor = 1000;
    +    this.periodsPerHour = 4;
    +  }
    +
    +  public SaltyRowKeyBuilder(int saltDivisor, int periodsPerHour) {
    +    this.saltDivisor = saltDivisor;
    +    this.periodsPerHour = periodsPerHour;
    +  }
    +
    +  /**
    +   * Builds a list of row keys necessary to retrieve profile measurements over
    +   * a time horizon.
    +   *
    +   * @param profile The name of the profile.
    +   * @param entity The name of the entity.
    +   * @param groups The group(s) used to sort the profile data.
    +   * @param durationAgo How long ago?
    +   * @param unit The time units of how long ago.
    +   * @return All of the row keys necessary to retrieve the profile measurements.
    +   */
    +  @Override
    +  public List<byte[]> rowKeys(String profile, String entity, List<Object> groups, long durationAgo, TimeUnit unit) {
    --- End diff --
    
    Nah, I was thinking that we might compare output of a given profile against a lookback not including the current range for outlier analysis (i.e. comparing the current profile period against the profile period of the last month trailing the current profile period).


---
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 #236: METRON-389 Create Java API to Read Profi...

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/236#discussion_r78374098
  
    --- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/hbase/Serializer.java ---
    @@ -0,0 +1,92 @@
    +/*
    + *
    + *  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.hbase;
    +
    +import org.apache.hadoop.hbase.util.Bytes;
    +
    +/**
    + * Provides basic functionality to serialize and deserialize the allowed
    + * value types for a ProfileMeasurement.
    + */
    +public class Serializer {
    +
    +  private Serializer() {
    +    // do not instantiate
    +  }
    +
    +  /**
    +   * Serialize a profile measurement's value.
    +   *
    +   * The value produced by a Profile definition can be any numeric data type.  The data
    +   * type depends on how the profile is defined by the user.  The user should be able to
    +   * choose the data type that is most suitable for their use case.
    +   *
    +   * @param value The value to serialize.
    +   */
    +  public static byte[] toBytes(Object value) {
    --- End diff --
    
    I don't see a strong reason to stress about it as long as it gets done in a follow-on PR at the end of the pipeline.  Do me a favor and evaluate the impact, though.


---
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 #236: METRON-389 Create Java API to Read Profi...

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/236#discussion_r76795784
  
    --- Diff: metron-analytics/metron-profiler/src/main/flux/profiler/remote.yaml ---
    @@ -25,11 +25,28 @@ components:
         -   id: "defaultExecutor"
             className: "org.apache.metron.profiler.stellar.DefaultStellarExecutor"
     
    -    -   id: "hbaseMapper"
    -        className: "org.apache.metron.profiler.bolt.ProfileHBaseMapper"
    +    -   id: "rowKeyBuilder"
    +        className: "org.apache.metron.profiler.hbase.SaltyRowKeyBuilder"
             properties:
                 - name: "saltDivisor"
                   value: ${profiler.hbase.salt.divisor}
    +            - name: "periodsPerHour"
    +              value: ${profiler.periods.per.hour}
    +
    +    -   id: "columnBuilder"
    +        className: "org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder"
    +        constructorArgs:
    +            - "${profiler.hbase.column.family}"
    +
    +    -   id: "hbaseMapper"
    +        className: "org.apache.metron.profiler.bolt.ProfileHBaseMapper"
    +        properties:
    +            - name: "rowKeyBuilder"
    +              ref: "rowKeyBuilder"
    +            - name: "columnBuilder"
    +              ref: "columnBuilder"
    +            - name: "executor"
    +              ref: "defaultExecutor"
    --- End diff --
    
    I have multiple components that each need their own `StellarExecutor`. Does Flux treat the `defaultExecutor` reference as a singleton and so every reference to `defaultExecutor` is pointing to the same object?  Or is treated more like a Spring Bean's 'Prototype' scope?  I would think it would have to be treated as a prototype, but I'd like to make sure.


---
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 #236: METRON-389 Create Java API to Read Profi...

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/236#discussion_r78376795
  
    --- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/hbase/SaltyRowKeyBuilder.java ---
    @@ -0,0 +1,211 @@
    +/*
    + *
    + *  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.hbase;
    +
    +import org.apache.hadoop.hbase.util.Bytes;
    +import org.apache.metron.profiler.ProfileMeasurement;
    +import org.apache.metron.profiler.ProfilePeriod;
    +
    +import java.nio.ByteBuffer;
    +import java.security.MessageDigest;
    +import java.security.NoSuchAlgorithmException;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.concurrent.TimeUnit;
    +
    +/**
    + * A RowKeyBuilder that uses a salt to prevent hot-spotting.
    + *
    + * Responsible for building the row keys used to store profile data in HBase.  The row key is composed of the following
    + * fields in the given order.
    + * <ul>
    + * <li>salt - A salt that helps prevent hot-spotting.
    + * <li>profile - The name of the profile.
    + * <li>entity - The name of the entity being profiled.
    + * <li>group(s) - The group(s) used to sort the data in HBase. For example, a group may distinguish between weekends and weekdays.
    + * <li>year - The year based on UTC.
    + * <li>day of year - The current day within the year based on UTC; [1, 366]
    + * <li>hour - The hour within the day based on UTC; [0, 23]
    + * </ul>period - The period within the hour.  The number of periods per hour can be defined by the user; defaults to 4.
    + */
    +public class SaltyRowKeyBuilder implements RowKeyBuilder {
    +
    +  /**
    +   * A salt can be prepended to the row key to help prevent hot-spotting.  The salt
    +   * divisor is used to generate the salt.  The salt divisor should be roughly equal
    +   * to the number of nodes in the Hbase cluster.
    +   */
    +  private int saltDivisor;
    +
    +  /**
    +   * An hour is divided into multiple periods.  This defines how many periods
    +   * will exist within each given hour.
    +   */
    +  private int periodsPerHour;
    +
    +  public SaltyRowKeyBuilder() {
    +    this.saltDivisor = 1000;
    +    this.periodsPerHour = 4;
    +  }
    +
    +  public SaltyRowKeyBuilder(int saltDivisor, int periodsPerHour) {
    +    this.saltDivisor = saltDivisor;
    +    this.periodsPerHour = periodsPerHour;
    +  }
    +
    +  /**
    +   * Builds a list of row keys necessary to retrieve profile measurements over
    +   * a time horizon.
    +   *
    +   * @param profile The name of the profile.
    +   * @param entity The name of the entity.
    +   * @param groups The group(s) used to sort the profile data.
    +   * @param durationAgo How long ago?
    +   * @param unit The time units of how long ago.
    +   * @return All of the row keys necessary to retrieve the profile measurements.
    +   */
    +  @Override
    +  public List<byte[]> rowKeys(String profile, String entity, List<Object> groups, long durationAgo, TimeUnit unit) {
    --- End diff --
    
    Added [METRON-413](https://issues.apache.org/jira/browse/METRON-413) to track this change.


---
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 #236: METRON-389 Create Java API to Read Profi...

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/236#discussion_r78367857
  
    --- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/bolt/ProfileBuilderBolt.java ---
    @@ -100,7 +101,11 @@ public ProfileBuilderBolt(String zookeeperUrl) {
       @Override
       public Map<String, Object> getComponentConfiguration() {
         Config conf = new Config();
    -    conf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, getFlushFrequency());
    +
    +    // how frequently should the bold receive tick tuples?
    --- End diff --
    
    s/bold/bolt


---
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 #236: METRON-389 Create Java API to Read Profi...

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/236#discussion_r78369111
  
    --- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/hbase/SaltyRowKeyBuilder.java ---
    @@ -0,0 +1,211 @@
    +/*
    + *
    + *  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.hbase;
    +
    +import org.apache.hadoop.hbase.util.Bytes;
    +import org.apache.metron.profiler.ProfileMeasurement;
    +import org.apache.metron.profiler.ProfilePeriod;
    +
    +import java.nio.ByteBuffer;
    +import java.security.MessageDigest;
    +import java.security.NoSuchAlgorithmException;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.concurrent.TimeUnit;
    +
    +/**
    + * A RowKeyBuilder that uses a salt to prevent hot-spotting.
    + *
    + * Responsible for building the row keys used to store profile data in HBase.  The row key is composed of the following
    + * fields in the given order.
    + * <ul>
    + * <li>salt - A salt that helps prevent hot-spotting.
    + * <li>profile - The name of the profile.
    + * <li>entity - The name of the entity being profiled.
    + * <li>group(s) - The group(s) used to sort the data in HBase. For example, a group may distinguish between weekends and weekdays.
    + * <li>year - The year based on UTC.
    + * <li>day of year - The current day within the year based on UTC; [1, 366]
    + * <li>hour - The hour within the day based on UTC; [0, 23]
    + * </ul>period - The period within the hour.  The number of periods per hour can be defined by the user; defaults to 4.
    + */
    +public class SaltyRowKeyBuilder implements RowKeyBuilder {
    +
    +  /**
    +   * A salt can be prepended to the row key to help prevent hot-spotting.  The salt
    +   * divisor is used to generate the salt.  The salt divisor should be roughly equal
    +   * to the number of nodes in the Hbase cluster.
    +   */
    +  private int saltDivisor;
    +
    +  /**
    +   * An hour is divided into multiple periods.  This defines how many periods
    +   * will exist within each given hour.
    +   */
    +  private int periodsPerHour;
    +
    +  public SaltyRowKeyBuilder() {
    +    this.saltDivisor = 1000;
    +    this.periodsPerHour = 4;
    +  }
    +
    +  public SaltyRowKeyBuilder(int saltDivisor, int periodsPerHour) {
    +    this.saltDivisor = saltDivisor;
    +    this.periodsPerHour = periodsPerHour;
    +  }
    +
    +  /**
    +   * Builds a list of row keys necessary to retrieve profile measurements over
    +   * a time horizon.
    +   *
    +   * @param profile The name of the profile.
    +   * @param entity The name of the entity.
    +   * @param groups The group(s) used to sort the profile data.
    +   * @param durationAgo How long ago?
    +   * @param unit The time units of how long ago.
    +   * @return All of the row keys necessary to retrieve the profile measurements.
    +   */
    +  @Override
    +  public List<byte[]> rowKeys(String profile, String entity, List<Object> groups, long durationAgo, TimeUnit unit) {
    --- End diff --
    
    Is there a reason why we do not have a method on RowKeyBuilder which takes an arbitrary start and end time?


---
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 #236: METRON-389 Create Java API to Read Profi...

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/236#discussion_r78369468
  
    --- Diff: metron-analytics/metron-profiler/src/main/java/org/apache/metron/profiler/bolt/ProfileBuilderBolt.java ---
    @@ -194,8 +194,8 @@ private void init(Tuple input) {
           expressions.forEach((var, expr) -> executor.assign(var, expr, message));
     
         } catch(ParseException e) {
    -      String msg = format("Bad 'init' expression: %s, profile=%s, entity=%s, start=%d",
    -              e.getMessage(), measurement.getProfileName(), measurement.getEntity(), measurement.getStart());
    +      String msg = format("Bad 'init' expression: %s, profile=%s, entity=%s",
    +              e.getMessage(), measurement.getProfileName(), measurement.getEntity());
    --- End diff --
    
    Yes, they already are LOG.error'd inside `execute`.  
    
    The point of this catch is to add the extra note that the failure came from the 'init' expression, rather than one of the other expressions involved in creating a profile.  I wanted to make it blatantly obvious to the user which expression failed.


---
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.
---