Uploaded image for project: 'Metron'
  1. Metron
  2. METRON-1005

Create Decodable Row Key for Profiler

    Details

    • Type: Improvement
    • Status: To Do
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 0.3.0
    • Fix Version/s: Next + 1
    • Labels:
      None

      Description

      To be able to answer the types of questions that I outlined in METRON-450, we need a row key that is decodable. Right now there is no logic to decode a row key, nor is the existing row key easily decodable.

      Once the row keys can be decoded, you could scan all of the row keys in the Profiler's HBase table, decode each of them and extract things like, the names of all your profiles, the names of entities within a profile, the period duration of a given profile.

        Issue Links

          Activity

          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user nickwallen opened a pull request:

          https://github.com/apache/metron/pull/622

          METRON-1005 Create Decodable Row Key for Profiler

          To be able to answer the types of questions that I outlined in METRON-450(https://issues.apache.org/jira/browse/METRON-450), we need a row key that is decodable. Right now there is no logic to decode a row key, nor is the existing row key easily decodable.

          Once the row keys can be decoded, you could scan all of the row keys in the Profiler's HBase table, decode each of them and extract things like, the names of all your profiles, the names of entities within a profile, the period duration of a given profile.

          • [ ] Do not merge. Opening this PR for review and feedback. I still need to run this through manual testing.
          • [ ] *WARNING*: This change is NOT backwards compatible. The row key format has changed. All data written with the legacy row key cannot be read by the new code in this PR. Should I make this backwards compatible? I could make these changes live in a new `RowKeyBuilder` implementation, which would allow for backwards compatibility.
            1. Pull Request Checklist
          • [x] Is there a JIRA ticket associated with this PR? If not one needs to be created at [Metron Jira](https://issues.apache.org/jira/browse/METRON/?selectedTab=com.atlassian.jira.jira-projects-plugin:summary-panel).
          • [x] Does your PR title start with METRON-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
          • [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
          • [ ] Have you included steps to reproduce the behavior or problem that is being changed or addressed?
          • [ ] Have you included steps or a guide to how the change may be verified and tested manually?
          • [x] Have you ensured that the full suite of tests and checks have been executed in the root incubating-metron folder via:
          • [x] Have you written or updated unit tests and or integration tests to verify your changes?
          • [ ] Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent?

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

          $ git pull https://github.com/nickwallen/metron METRON-1005

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

          https://github.com/apache/metron/pull/622.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 #622


          commit edd7fa6946b4bcb5975c8497ab5550201718e426
          Author: Nick Allen <nick@nickallen.org>
          Date: 2017-06-22T21:45:40Z

          METRON-1005 Create Decodable Row Key for Profiler


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user nickwallen opened a pull request: https://github.com/apache/metron/pull/622 METRON-1005 Create Decodable Row Key for Profiler To be able to answer the types of questions that I outlined in METRON-450 ( https://issues.apache.org/jira/browse/METRON-450 ), we need a row key that is decodable. Right now there is no logic to decode a row key, nor is the existing row key easily decodable. Once the row keys can be decoded, you could scan all of the row keys in the Profiler's HBase table, decode each of them and extract things like, the names of all your profiles, the names of entities within a profile, the period duration of a given profile. [ ] Do not merge. Opening this PR for review and feedback. I still need to run this through manual testing. [ ] * WARNING *: This change is NOT backwards compatible. The row key format has changed. All data written with the legacy row key cannot be read by the new code in this PR. Should I make this backwards compatible? I could make these changes live in a new `RowKeyBuilder` implementation, which would allow for backwards compatibility. Pull Request Checklist [x] Is there a JIRA ticket associated with this PR? If not one needs to be created at [Metron Jira] ( https://issues.apache.org/jira/browse/METRON/?selectedTab=com.atlassian.jira.jira-projects-plugin:summary-panel ). [x] Does your PR title start with METRON-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character. [x] Has your PR been rebased against the latest commit within the target branch (typically master)? [ ] Have you included steps to reproduce the behavior or problem that is being changed or addressed? [ ] Have you included steps or a guide to how the change may be verified and tested manually? [x] Have you ensured that the full suite of tests and checks have been executed in the root incubating-metron folder via: [x] Have you written or updated unit tests and or integration tests to verify your changes? [ ] Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent? You can merge this pull request into a Git repository by running: $ git pull https://github.com/nickwallen/metron METRON-1005 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/metron/pull/622.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 #622 commit edd7fa6946b4bcb5975c8497ab5550201718e426 Author: Nick Allen <nick@nickallen.org> Date: 2017-06-22T21:45:40Z METRON-1005 Create Decodable Row Key for Profiler
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user cestella commented on the issue:

          https://github.com/apache/metron/pull/622

          I strongly vote that you move these changes to a new RowKeyBuilder and keep the old one default until a major release. The sad thing is, I don't think there is a way to migrate the old data, so we're kinda screwed here in terms of backwards compatibility. I definitely agree that we should move to a profiler row key that is decodable, though, so it's very good work @nickwallen .

          Show
          githubbot ASF GitHub Bot added a comment - Github user cestella commented on the issue: https://github.com/apache/metron/pull/622 I strongly vote that you move these changes to a new RowKeyBuilder and keep the old one default until a major release. The sad thing is, I don't think there is a way to migrate the old data, so we're kinda screwed here in terms of backwards compatibility. I definitely agree that we should move to a profiler row key that is decodable, though, so it's very good work @nickwallen .
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nickwallen commented on a diff in the pull request:

          https://github.com/apache/metron/pull/622#discussion_r127325245

          — Diff: metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/RowKeyBuilderFactory.java —
          @@ -0,0 +1,125 @@
          +/*
          + *
          + * 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.client.stellar;
          +
          +import org.apache.commons.beanutils.PropertyUtils;
          +import org.apache.commons.lang3.ClassUtils;
          +import org.apache.metron.common.utils.ReflectionUtils;
          +import org.apache.metron.profiler.hbase.RowKeyBuilder;
          +import org.slf4j.Logger;
          +import org.slf4j.LoggerFactory;
          +
          +import java.lang.reflect.InvocationTargetException;
          +import java.util.Map;
          +import java.util.concurrent.TimeUnit;
          +
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD;
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD_UNITS;
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_ROW_KEY_BUILDER;
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_SALT_DIVISOR;
          +
          +/**
          + * A Factory class that can create a RowKeyBuilder based on global property values.
          + */
          +public class RowKeyBuilderFactory {
          +
          + private static final Logger LOG = LoggerFactory.getLogger(RowKeyBuilderFactory.class);
          +
          + /**
          + * Create a RowKeyBuilder.
          + * @param global The global properties.
          + * @return A RowKeyBuilder instantiated using the global property values.
          + */
          + public static RowKeyBuilder create(Map<String, Object> global) {
          + String rowKeyBuilderClass = PROFILER_ROW_KEY_BUILDER.get(global, String.class);
          + LOG.debug("profiler client: {}={}", PROFILER_ROW_KEY_BUILDER, rowKeyBuilderClass);
          +
          + // instantiate the RowKeyBuilder
          + RowKeyBuilder builder = ReflectionUtils.createInstance(rowKeyBuilderClass);
          + setSaltDivisor(global, builder);
          + setPeriodDuration(global, builder);
          — End diff –

          Here is the logic to instantiate a `RowKeyBuilder` that is used by the Profiler Client's `GetProfile`.

          Show
          githubbot ASF GitHub Bot added a comment - Github user nickwallen commented on a diff in the pull request: https://github.com/apache/metron/pull/622#discussion_r127325245 — Diff: metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/RowKeyBuilderFactory.java — @@ -0,0 +1,125 @@ +/* + * + * 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.client.stellar; + +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.lang3.ClassUtils; +import org.apache.metron.common.utils.ReflectionUtils; +import org.apache.metron.profiler.hbase.RowKeyBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.InvocationTargetException; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD; +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD_UNITS; +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_ROW_KEY_BUILDER; +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_SALT_DIVISOR; + +/** + * A Factory class that can create a RowKeyBuilder based on global property values. + */ +public class RowKeyBuilderFactory { + + private static final Logger LOG = LoggerFactory.getLogger(RowKeyBuilderFactory.class); + + /** + * Create a RowKeyBuilder. + * @param global The global properties. + * @return A RowKeyBuilder instantiated using the global property values. + */ + public static RowKeyBuilder create(Map<String, Object> global) { + String rowKeyBuilderClass = PROFILER_ROW_KEY_BUILDER.get(global, String.class); + LOG.debug("profiler client: {}={}", PROFILER_ROW_KEY_BUILDER, rowKeyBuilderClass); + + // instantiate the RowKeyBuilder + RowKeyBuilder builder = ReflectionUtils.createInstance(rowKeyBuilderClass); + setSaltDivisor(global, builder); + setPeriodDuration(global, builder); — End diff – Here is the logic to instantiate a `RowKeyBuilder` that is used by the Profiler Client's `GetProfile`.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nickwallen commented on a diff in the pull request:

          https://github.com/apache/metron/pull/622#discussion_r127326600

          — Diff: metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/RowKeyBuilderFactory.java —
          @@ -0,0 +1,125 @@
          +/*
          + *
          + * 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.client.stellar;
          +
          +import org.apache.commons.beanutils.PropertyUtils;
          +import org.apache.commons.lang3.ClassUtils;
          +import org.apache.metron.common.utils.ReflectionUtils;
          +import org.apache.metron.profiler.hbase.RowKeyBuilder;
          +import org.slf4j.Logger;
          +import org.slf4j.LoggerFactory;
          +
          +import java.lang.reflect.InvocationTargetException;
          +import java.util.Map;
          +import java.util.concurrent.TimeUnit;
          +
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD;
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD_UNITS;
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_ROW_KEY_BUILDER;
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_SALT_DIVISOR;
          +
          +/**
          + * A Factory class that can create a RowKeyBuilder based on global property values.
          + */
          +public class RowKeyBuilderFactory {
          +
          + private static final Logger LOG = LoggerFactory.getLogger(RowKeyBuilderFactory.class);
          +
          + /**
          + * Create a RowKeyBuilder.
          + * @param global The global properties.
          + * @return A RowKeyBuilder instantiated using the global property values.
          + */
          + public static RowKeyBuilder create(Map<String, Object> global) {
          + String rowKeyBuilderClass = PROFILER_ROW_KEY_BUILDER.get(global, String.class);
          + LOG.debug("profiler client: {}={}", PROFILER_ROW_KEY_BUILDER, rowKeyBuilderClass);
          +
          + // instantiate the RowKeyBuilder
          + RowKeyBuilder builder = ReflectionUtils.createInstance(rowKeyBuilderClass);
          + setSaltDivisor(global, builder);
          + setPeriodDuration(global, builder);
          — End diff –

          But I think this actually turned out worse, than the alternative of just adding `RowKeyBuilder.setSaltDivisor` and polluting the interface.

          Show
          githubbot ASF GitHub Bot added a comment - Github user nickwallen commented on a diff in the pull request: https://github.com/apache/metron/pull/622#discussion_r127326600 — Diff: metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/RowKeyBuilderFactory.java — @@ -0,0 +1,125 @@ +/* + * + * 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.client.stellar; + +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.lang3.ClassUtils; +import org.apache.metron.common.utils.ReflectionUtils; +import org.apache.metron.profiler.hbase.RowKeyBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.InvocationTargetException; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD; +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD_UNITS; +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_ROW_KEY_BUILDER; +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_SALT_DIVISOR; + +/** + * A Factory class that can create a RowKeyBuilder based on global property values. + */ +public class RowKeyBuilderFactory { + + private static final Logger LOG = LoggerFactory.getLogger(RowKeyBuilderFactory.class); + + /** + * Create a RowKeyBuilder. + * @param global The global properties. + * @return A RowKeyBuilder instantiated using the global property values. + */ + public static RowKeyBuilder create(Map<String, Object> global) { + String rowKeyBuilderClass = PROFILER_ROW_KEY_BUILDER.get(global, String.class); + LOG.debug("profiler client: {}={}", PROFILER_ROW_KEY_BUILDER, rowKeyBuilderClass); + + // instantiate the RowKeyBuilder + RowKeyBuilder builder = ReflectionUtils.createInstance(rowKeyBuilderClass); + setSaltDivisor(global, builder); + setPeriodDuration(global, builder); — End diff – But I think this actually turned out worse, than the alternative of just adding `RowKeyBuilder.setSaltDivisor` and polluting the interface.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nickwallen commented on a diff in the pull request:

          https://github.com/apache/metron/pull/622#discussion_r127327126

          — Diff: metron-analytics/metron-profiler/src/main/flux/profiler/remote.yaml —
          @@ -29,7 +29,7 @@ components:

          • name: "saltDivisor"
              • End diff –

          Notice that the legacy `RowKeyBuilder`, the `SaltyRowKeyBuilder`, is still the default. If a user wants to use the new `RowKeyBuilder` then they need to change the flux file here and specify `org.apache.metron.profiler.hbase.DecodableRowKeyBuilder`.

          Show
          githubbot ASF GitHub Bot added a comment - Github user nickwallen commented on a diff in the pull request: https://github.com/apache/metron/pull/622#discussion_r127327126 — Diff: metron-analytics/metron-profiler/src/main/flux/profiler/remote.yaml — @@ -29,7 +29,7 @@ components: name: "saltDivisor" End diff – Notice that the legacy `RowKeyBuilder`, the `SaltyRowKeyBuilder`, is still the default. If a user wants to use the new `RowKeyBuilder` then they need to change the flux file here and specify `org.apache.metron.profiler.hbase.DecodableRowKeyBuilder`.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nickwallen commented on a diff in the pull request:

          https://github.com/apache/metron/pull/622#discussion_r127327990

          — Diff: metron-analytics/metron-profiler/src/main/flux/profiler/remote.yaml —
          @@ -29,7 +29,7 @@ components:

          • name: "saltDivisor"
              • End diff –

          I chose to require a flux file change here because this is not something that any old user should just change. This is only configurable to allow for backwards compatibility.

          In addition, the IoC-like functionality that Flux provides makes it easier to set whatever configuration values are needed by a `RowKeyBuilder` (like salt divisor) without polluting the `RowKeyBuilder` interface.

          There is no such convenient IoC-like functionality when trying to instantiate the `RowKeyBuilder` from the client-side in `GetProfile`.

          Show
          githubbot ASF GitHub Bot added a comment - Github user nickwallen commented on a diff in the pull request: https://github.com/apache/metron/pull/622#discussion_r127327990 — Diff: metron-analytics/metron-profiler/src/main/flux/profiler/remote.yaml — @@ -29,7 +29,7 @@ components: name: "saltDivisor" End diff – I chose to require a flux file change here because this is not something that any old user should just change. This is only configurable to allow for backwards compatibility. In addition, the IoC-like functionality that Flux provides makes it easier to set whatever configuration values are needed by a `RowKeyBuilder` (like salt divisor) without polluting the `RowKeyBuilder` interface. There is no such convenient IoC-like functionality when trying to instantiate the `RowKeyBuilder` from the client-side in `GetProfile`.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nickwallen commented on a diff in the pull request:

          https://github.com/apache/metron/pull/622#discussion_r127329548

          — Diff: metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/hbase/DecodableRowKeyBuilder.java —
          @@ -0,0 +1,382 @@
          +/*
          + *
          + * 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.BufferUnderflowException;
          +import java.nio.ByteBuffer;
          +import java.nio.ByteOrder;
          +import java.security.MessageDigest;
          +import java.security.NoSuchAlgorithmException;
          +import java.util.ArrayList;
          +import java.util.List;
          +import java.util.Optional;
          +import java.util.concurrent.TimeUnit;
          +
          +/**
          + * Responsible for building the row keys used to store profile data in HBase.
          + *
          + * This builder generates decodable row keys. A decodable row key is one that can be interrogated to extract
          + * the constituent components of that row key. Given a previously generated row key this builder
          + * can extract the profile name, entity name, group name(s), period duration, and period.
          + *
          + * The row key is composed of the following fields.
          + * <ul>
          + * <li>magic number - Helps to validate the row key.</li>
          + * <li>version - The version number of the row key.</li>
          + * <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>period - The period in which the measurement was taken. The first period starts at the epoch and increases monotonically.
          + * </ul>
          + */
          +public class DecodableRowKeyBuilder implements RowKeyBuilder {
          — End diff –

          The new `RowKeyBuilder` implementation that is decodable. Everyone should just use this, but the older implementation is left for backwards compatibility.

          Show
          githubbot ASF GitHub Bot added a comment - Github user nickwallen commented on a diff in the pull request: https://github.com/apache/metron/pull/622#discussion_r127329548 — Diff: metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/hbase/DecodableRowKeyBuilder.java — @@ -0,0 +1,382 @@ +/* + * + * 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.BufferUnderflowException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.TimeUnit; + +/** + * Responsible for building the row keys used to store profile data in HBase. + * + * This builder generates decodable row keys. A decodable row key is one that can be interrogated to extract + * the constituent components of that row key. Given a previously generated row key this builder + * can extract the profile name, entity name, group name(s), period duration, and period. + * + * The row key is composed of the following fields. + * <ul> + * <li>magic number - Helps to validate the row key.</li> + * <li>version - The version number of the row key.</li> + * <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>period - The period in which the measurement was taken. The first period starts at the epoch and increases monotonically. + * </ul> + */ +public class DecodableRowKeyBuilder implements RowKeyBuilder { — End diff – The new `RowKeyBuilder` implementation that is decodable. Everyone should just use this, but the older implementation is left for backwards compatibility.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nickwallen commented on a diff in the pull request:

          https://github.com/apache/metron/pull/622#discussion_r127329289

          — Diff: metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/RowKeyBuilderFactory.java —
          @@ -0,0 +1,125 @@
          +/*
          + *
          + * 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.client.stellar;
          +
          +import org.apache.commons.beanutils.PropertyUtils;
          +import org.apache.commons.lang3.ClassUtils;
          +import org.apache.metron.common.utils.ReflectionUtils;
          +import org.apache.metron.profiler.hbase.RowKeyBuilder;
          +import org.slf4j.Logger;
          +import org.slf4j.LoggerFactory;
          +
          +import java.lang.reflect.InvocationTargetException;
          +import java.util.Map;
          +import java.util.concurrent.TimeUnit;
          +
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD;
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD_UNITS;
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_ROW_KEY_BUILDER;
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_SALT_DIVISOR;
          +
          +/**
          + * A Factory class that can create a RowKeyBuilder based on global property values.
          + */
          +public class RowKeyBuilderFactory {
          +
          + private static final Logger LOG = LoggerFactory.getLogger(RowKeyBuilderFactory.class);
          +
          + /**
          + * Create a RowKeyBuilder.
          + * @param global The global properties.
          + * @return A RowKeyBuilder instantiated using the global property values.
          + */
          + public static RowKeyBuilder create(Map<String, Object> global) {
          + String rowKeyBuilderClass = PROFILER_ROW_KEY_BUILDER.get(global, String.class);
          + LOG.debug("profiler client: {}={}", PROFILER_ROW_KEY_BUILDER, rowKeyBuilderClass);
          +
          + // instantiate the RowKeyBuilder
          + RowKeyBuilder builder = ReflectionUtils.createInstance(rowKeyBuilderClass);
          + setSaltDivisor(global, builder);
          + setPeriodDuration(global, builder);
          +
          + return builder;
          + }
          +
          + /**
          + * Set the period duration on the RowKeyBuilder.
          + * @param global The global properties from Zk.
          + * @param builder The RowKeyBuilder implementation.
          + */
          + private static void setPeriodDuration(Map<String, Object> global, RowKeyBuilder builder) {
          +
          + // how long is the profile period?
          + long duration = PROFILER_PERIOD.get(global, Long.class);
          + LOG.debug("profiler client: {}={}", PROFILER_PERIOD, duration);
          +
          + // which units are used to define the profile period?
          + String configuredUnits = PROFILER_PERIOD_UNITS.get(global, String.class);
          + TimeUnit units = TimeUnit.valueOf(configuredUnits);
          + LOG.debug("profiler client: {}={}", PROFILER_PERIOD_UNITS, units);
          +
          + // set the period duration
          + final String periodDurationProperty = "periodDurationMillis";
          + setProperty(builder, periodDurationProperty, units.toMillis(duration));
          + }
          +
          + /**
          + * Set the salt divisor property on the RowKeyBuilder.
          + * @param global The global properties from Zk.
          + * @param builder The RowKeyBuilder implementation.
          + */
          + private static void setSaltDivisor(Map<String, Object> global, RowKeyBuilder builder) {
          +
          + // what is the salt divisor?
          + Integer saltDivisor = PROFILER_SALT_DIVISOR.get(global, Integer.class);
          + LOG.debug("profiler client: {}={}", PROFILER_SALT_DIVISOR, saltDivisor);
          +
          + final String saltDivisorProperty = "saltDivisor";
          + setProperty(builder, saltDivisorProperty, saltDivisor);
          — End diff –

          This basically sets the 'salt divisor' on any `RowKeyBuilder` that has a `saltDivisor` setter. I really don't like this. It is very hack-ish. I would love to use a simpler alternative.

          Show
          githubbot ASF GitHub Bot added a comment - Github user nickwallen commented on a diff in the pull request: https://github.com/apache/metron/pull/622#discussion_r127329289 — Diff: metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/RowKeyBuilderFactory.java — @@ -0,0 +1,125 @@ +/* + * + * 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.client.stellar; + +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.lang3.ClassUtils; +import org.apache.metron.common.utils.ReflectionUtils; +import org.apache.metron.profiler.hbase.RowKeyBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.InvocationTargetException; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD; +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD_UNITS; +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_ROW_KEY_BUILDER; +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_SALT_DIVISOR; + +/** + * A Factory class that can create a RowKeyBuilder based on global property values. + */ +public class RowKeyBuilderFactory { + + private static final Logger LOG = LoggerFactory.getLogger(RowKeyBuilderFactory.class); + + /** + * Create a RowKeyBuilder. + * @param global The global properties. + * @return A RowKeyBuilder instantiated using the global property values. + */ + public static RowKeyBuilder create(Map<String, Object> global) { + String rowKeyBuilderClass = PROFILER_ROW_KEY_BUILDER.get(global, String.class); + LOG.debug("profiler client: {}={}", PROFILER_ROW_KEY_BUILDER, rowKeyBuilderClass); + + // instantiate the RowKeyBuilder + RowKeyBuilder builder = ReflectionUtils.createInstance(rowKeyBuilderClass); + setSaltDivisor(global, builder); + setPeriodDuration(global, builder); + + return builder; + } + + /** + * Set the period duration on the RowKeyBuilder. + * @param global The global properties from Zk. + * @param builder The RowKeyBuilder implementation. + */ + private static void setPeriodDuration(Map<String, Object> global, RowKeyBuilder builder) { + + // how long is the profile period? + long duration = PROFILER_PERIOD.get(global, Long.class); + LOG.debug("profiler client: {}={}", PROFILER_PERIOD, duration); + + // which units are used to define the profile period? + String configuredUnits = PROFILER_PERIOD_UNITS.get(global, String.class); + TimeUnit units = TimeUnit.valueOf(configuredUnits); + LOG.debug("profiler client: {}={}", PROFILER_PERIOD_UNITS, units); + + // set the period duration + final String periodDurationProperty = "periodDurationMillis"; + setProperty(builder, periodDurationProperty, units.toMillis(duration)); + } + + /** + * Set the salt divisor property on the RowKeyBuilder. + * @param global The global properties from Zk. + * @param builder The RowKeyBuilder implementation. + */ + private static void setSaltDivisor(Map<String, Object> global, RowKeyBuilder builder) { + + // what is the salt divisor? + Integer saltDivisor = PROFILER_SALT_DIVISOR.get(global, Integer.class); + LOG.debug("profiler client: {}={}", PROFILER_SALT_DIVISOR, saltDivisor); + + final String saltDivisorProperty = "saltDivisor"; + setProperty(builder, saltDivisorProperty, saltDivisor); — End diff – This basically sets the 'salt divisor' on any `RowKeyBuilder` that has a `saltDivisor` setter. I really don't like this. It is very hack-ish. I would love to use a simpler alternative.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nickwallen commented on a diff in the pull request:

          https://github.com/apache/metron/pull/622#discussion_r127329675

          — Diff: metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/hbase/SaltyRowKeyBuilder.java —
          @@ -44,7 +46,17 @@

          • <li>group(s) - The group(s) used to sort the data in HBase. For example, a group may distinguish between weekends and weekdays.
          • <li>period - The period in which the measurement was taken. The first period starts at the epoch and increases monotonically.
          • </ul>
            + *
            + * This row key builder has no logic to decode a row key, nor is the row key generated by this builder
            + * easily decodable. More specifically, the profile, entity, groups and period that make up the row key
            + * cannot be extracted from a previously generated row key. This makes it difficult to answer questions
            + * like; What entities are included in this profile? What is the period for this profile? Use the
            + * DecodableRowKeyBuilder instead.
            + *
            + * @deprecated Replaced by DecodableRowKeyBuilder
            + * @see DecodableRowKeyBuilder
            */
            +@Deprecated
            public class SaltyRowKeyBuilder implements RowKeyBuilder {
              • End diff –

          I marked the old `RowKeyBuilder` as deprecated.

          Show
          githubbot ASF GitHub Bot added a comment - Github user nickwallen commented on a diff in the pull request: https://github.com/apache/metron/pull/622#discussion_r127329675 — Diff: metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/hbase/SaltyRowKeyBuilder.java — @@ -44,7 +46,17 @@ <li>group(s) - The group(s) used to sort the data in HBase. For example, a group may distinguish between weekends and weekdays. <li>period - The period in which the measurement was taken. The first period starts at the epoch and increases monotonically. </ul> + * + * This row key builder has no logic to decode a row key, nor is the row key generated by this builder + * easily decodable. More specifically, the profile, entity, groups and period that make up the row key + * cannot be extracted from a previously generated row key. This makes it difficult to answer questions + * like; What entities are included in this profile? What is the period for this profile? Use the + * DecodableRowKeyBuilder instead. + * + * @deprecated Replaced by DecodableRowKeyBuilder + * @see DecodableRowKeyBuilder */ +@Deprecated public class SaltyRowKeyBuilder implements RowKeyBuilder { End diff – I marked the old `RowKeyBuilder` as deprecated.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nickwallen commented on a diff in the pull request:

          https://github.com/apache/metron/pull/622#discussion_r127326080

          — Diff: metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/RowKeyBuilderFactory.java —
          @@ -0,0 +1,125 @@
          +/*
          + *
          + * 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.client.stellar;
          +
          +import org.apache.commons.beanutils.PropertyUtils;
          +import org.apache.commons.lang3.ClassUtils;
          +import org.apache.metron.common.utils.ReflectionUtils;
          +import org.apache.metron.profiler.hbase.RowKeyBuilder;
          +import org.slf4j.Logger;
          +import org.slf4j.LoggerFactory;
          +
          +import java.lang.reflect.InvocationTargetException;
          +import java.util.Map;
          +import java.util.concurrent.TimeUnit;
          +
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD;
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD_UNITS;
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_ROW_KEY_BUILDER;
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_SALT_DIVISOR;
          +
          +/**
          + * A Factory class that can create a RowKeyBuilder based on global property values.
          + */
          +public class RowKeyBuilderFactory {
          +
          + private static final Logger LOG = LoggerFactory.getLogger(RowKeyBuilderFactory.class);
          +
          + /**
          + * Create a RowKeyBuilder.
          + * @param global The global properties.
          + * @return A RowKeyBuilder instantiated using the global property values.
          + */
          + public static RowKeyBuilder create(Map<String, Object> global) {
          + String rowKeyBuilderClass = PROFILER_ROW_KEY_BUILDER.get(global, String.class);
          + LOG.debug("profiler client: {}={}", PROFILER_ROW_KEY_BUILDER, rowKeyBuilderClass);
          +
          + // instantiate the RowKeyBuilder
          + RowKeyBuilder builder = ReflectionUtils.createInstance(rowKeyBuilderClass);
          + setSaltDivisor(global, builder);
          + setPeriodDuration(global, builder);
          — End diff –

          I don't really like how I go about setting the salt divisor and period duration on the `RowKeyBuilder`. There are no methods in the `RowKeyBuilder` interface to do set these values. I could add something like `RowKeyBuilder.setSaltDivisor`, but I was trying not to pollute that interface with variables like salt divisor that may not apply to all RowKeyBuilder implementations.

          Show
          githubbot ASF GitHub Bot added a comment - Github user nickwallen commented on a diff in the pull request: https://github.com/apache/metron/pull/622#discussion_r127326080 — Diff: metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/RowKeyBuilderFactory.java — @@ -0,0 +1,125 @@ +/* + * + * 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.client.stellar; + +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.lang3.ClassUtils; +import org.apache.metron.common.utils.ReflectionUtils; +import org.apache.metron.profiler.hbase.RowKeyBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.InvocationTargetException; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD; +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD_UNITS; +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_ROW_KEY_BUILDER; +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_SALT_DIVISOR; + +/** + * A Factory class that can create a RowKeyBuilder based on global property values. + */ +public class RowKeyBuilderFactory { + + private static final Logger LOG = LoggerFactory.getLogger(RowKeyBuilderFactory.class); + + /** + * Create a RowKeyBuilder. + * @param global The global properties. + * @return A RowKeyBuilder instantiated using the global property values. + */ + public static RowKeyBuilder create(Map<String, Object> global) { + String rowKeyBuilderClass = PROFILER_ROW_KEY_BUILDER.get(global, String.class); + LOG.debug("profiler client: {}={}", PROFILER_ROW_KEY_BUILDER, rowKeyBuilderClass); + + // instantiate the RowKeyBuilder + RowKeyBuilder builder = ReflectionUtils.createInstance(rowKeyBuilderClass); + setSaltDivisor(global, builder); + setPeriodDuration(global, builder); — End diff – I don't really like how I go about setting the salt divisor and period duration on the `RowKeyBuilder`. There are no methods in the `RowKeyBuilder` interface to do set these values. I could add something like `RowKeyBuilder.setSaltDivisor`, but I was trying not to pollute that interface with variables like salt divisor that may not apply to all RowKeyBuilder implementations.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nickwallen commented on a diff in the pull request:

          https://github.com/apache/metron/pull/622#discussion_r127330773

          — Diff: metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/hbase/DecodableRowKeyBuilder.java —
          @@ -0,0 +1,382 @@
          +/*
          + *
          + * 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.BufferUnderflowException;
          +import java.nio.ByteBuffer;
          +import java.nio.ByteOrder;
          +import java.security.MessageDigest;
          +import java.security.NoSuchAlgorithmException;
          +import java.util.ArrayList;
          +import java.util.List;
          +import java.util.Optional;
          +import java.util.concurrent.TimeUnit;
          +
          +/**
          + * Responsible for building the row keys used to store profile data in HBase.
          + *
          + * This builder generates decodable row keys. A decodable row key is one that can be interrogated to extract
          + * the constituent components of that row key. Given a previously generated row key this builder
          + * can extract the profile name, entity name, group name(s), period duration, and period.
          + *
          + * The row key is composed of the following fields.
          + * <ul>
          + * <li>magic number - Helps to validate the row key.</li>
          + * <li>version - The version number of the row key.</li>
          + * <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>period - The period in which the measurement was taken. The first period starts at the epoch and increases monotonically.
          + * </ul>
          + */
          +public class DecodableRowKeyBuilder implements RowKeyBuilder {
          +
          + /**
          + * Defines the byte order when encoding and decoding the row keys.
          + *
          + * Making this configurable is likely not necessary and is left as a practice exercise for the reader.
          + */
          + private static final ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
          +
          + /**
          + * Defines some level of sane max field length to avoid any shenanigans with oddly encoded row keys.
          + */
          + private static final int MAX_FIELD_LENGTH = 1000;
          +
          + /**
          + * A magic number embedded in each row key to help validate the row key and byte ordering when decoding.
          + */
          + protected static final short MAGIC_NUMBER = 77;
          +
          + /**
          + * The version number of the row keys supported by this builder.
          + */
          + protected static final byte VERSION = (byte) 1;
          — End diff –

          I added a `VERSION` field to the row key, hoping that this might help future changes to the `RowKeyBuilder`. With this, I could potentially start to parse the row key and then choose the right `RowKeyBuilder` implementation; the one used to create the row key. This would make row key changes seemless to users.

          Show
          githubbot ASF GitHub Bot added a comment - Github user nickwallen commented on a diff in the pull request: https://github.com/apache/metron/pull/622#discussion_r127330773 — Diff: metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/hbase/DecodableRowKeyBuilder.java — @@ -0,0 +1,382 @@ +/* + * + * 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.BufferUnderflowException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.TimeUnit; + +/** + * Responsible for building the row keys used to store profile data in HBase. + * + * This builder generates decodable row keys. A decodable row key is one that can be interrogated to extract + * the constituent components of that row key. Given a previously generated row key this builder + * can extract the profile name, entity name, group name(s), period duration, and period. + * + * The row key is composed of the following fields. + * <ul> + * <li>magic number - Helps to validate the row key.</li> + * <li>version - The version number of the row key.</li> + * <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>period - The period in which the measurement was taken. The first period starts at the epoch and increases monotonically. + * </ul> + */ +public class DecodableRowKeyBuilder implements RowKeyBuilder { + + /** + * Defines the byte order when encoding and decoding the row keys. + * + * Making this configurable is likely not necessary and is left as a practice exercise for the reader. + */ + private static final ByteOrder byteOrder = ByteOrder.BIG_ENDIAN; + + /** + * Defines some level of sane max field length to avoid any shenanigans with oddly encoded row keys. + */ + private static final int MAX_FIELD_LENGTH = 1000; + + /** + * A magic number embedded in each row key to help validate the row key and byte ordering when decoding. + */ + protected static final short MAGIC_NUMBER = 77; + + /** + * The version number of the row keys supported by this builder. + */ + protected static final byte VERSION = (byte) 1; — End diff – I added a `VERSION` field to the row key, hoping that this might help future changes to the `RowKeyBuilder`. With this, I could potentially start to parse the row key and then choose the right `RowKeyBuilder` implementation; the one used to create the row key. This would make row key changes seemless to users.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nickwallen commented on a diff in the pull request:

          https://github.com/apache/metron/pull/622#discussion_r127328660

          — Diff: metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/GetProfile.java —
          @@ -216,21 +211,7 @@ private ColumnBuilder getColumnBuilder(Map<String, Object> global) {

          • @param global The global configuration.
            */
            private RowKeyBuilder getRowKeyBuilder(Map<String, Object> global) {
            -
          • // how long is the profile period?
          • long duration = PROFILER_PERIOD.get(global, Long.class);
          • LOG.debug("profiler client: {}={}", PROFILER_PERIOD, duration);
            -
          • // which units are used to define the profile period?
          • String configuredUnits = PROFILER_PERIOD_UNITS.get(global, String.class);
          • TimeUnit units = TimeUnit.valueOf(configuredUnits);
          • LOG.debug("profiler client: {}={}", PROFILER_PERIOD_UNITS, units);
            -
          • // what is the salt divisor?
          • Integer saltDivisor = PROFILER_SALT_DIVISOR.get(global, Integer.class);
          • LOG.debug("profiler client: {}={}", PROFILER_SALT_DIVISOR, saltDivisor);
            -
          • return new SaltyRowKeyBuilder(saltDivisor, duration, units);
            + return RowKeyBuilderFactory.create(global);
              • End diff –

          This is where we need to instantiate the `RowKeyBuilder` for the Profiler Client API. Like I will discuss in another thread, the logic got complex and kind of nasty so I encapsulated it in its own `RowKeyBuilderFactory`. See that class for a further discussion as to why it is kind of nasty.

          Show
          githubbot ASF GitHub Bot added a comment - Github user nickwallen commented on a diff in the pull request: https://github.com/apache/metron/pull/622#discussion_r127328660 — Diff: metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/GetProfile.java — @@ -216,21 +211,7 @@ private ColumnBuilder getColumnBuilder(Map<String, Object> global) { @param global The global configuration. */ private RowKeyBuilder getRowKeyBuilder(Map<String, Object> global) { - // how long is the profile period? long duration = PROFILER_PERIOD.get(global, Long.class); LOG.debug("profiler client: {}={}", PROFILER_PERIOD, duration); - // which units are used to define the profile period? String configuredUnits = PROFILER_PERIOD_UNITS.get(global, String.class); TimeUnit units = TimeUnit.valueOf(configuredUnits); LOG.debug("profiler client: {}={}", PROFILER_PERIOD_UNITS, units); - // what is the salt divisor? Integer saltDivisor = PROFILER_SALT_DIVISOR.get(global, Integer.class); LOG.debug("profiler client: {}={}", PROFILER_SALT_DIVISOR, saltDivisor); - return new SaltyRowKeyBuilder(saltDivisor, duration, units); + return RowKeyBuilderFactory.create(global); End diff – This is where we need to instantiate the `RowKeyBuilder` for the Profiler Client API. Like I will discuss in another thread, the logic got complex and kind of nasty so I encapsulated it in its own `RowKeyBuilderFactory`. See that class for a further discussion as to why it is kind of nasty.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nickwallen commented on a diff in the pull request:

          https://github.com/apache/metron/pull/622#discussion_r127331446

          — Diff: metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/RowKeyBuilderFactory.java —
          @@ -0,0 +1,125 @@
          +/*
          + *
          + * 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.client.stellar;
          +
          +import org.apache.commons.beanutils.PropertyUtils;
          +import org.apache.commons.lang3.ClassUtils;
          +import org.apache.metron.common.utils.ReflectionUtils;
          +import org.apache.metron.profiler.hbase.RowKeyBuilder;
          +import org.slf4j.Logger;
          +import org.slf4j.LoggerFactory;
          +
          +import java.lang.reflect.InvocationTargetException;
          +import java.util.Map;
          +import java.util.concurrent.TimeUnit;
          +
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD;
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD_UNITS;
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_ROW_KEY_BUILDER;
          +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_SALT_DIVISOR;
          +
          +/**
          + * A Factory class that can create a RowKeyBuilder based on global property values.
          + */
          +public class RowKeyBuilderFactory {
          +
          + private static final Logger LOG = LoggerFactory.getLogger(RowKeyBuilderFactory.class);
          +
          + /**
          + * Create a RowKeyBuilder.
          + * @param global The global properties.
          + * @return A RowKeyBuilder instantiated using the global property values.
          + */
          + public static RowKeyBuilder create(Map<String, Object> global) {
          + String rowKeyBuilderClass = PROFILER_ROW_KEY_BUILDER.get(global, String.class);
          + LOG.debug("profiler client: {}={}", PROFILER_ROW_KEY_BUILDER, rowKeyBuilderClass);
          +
          + // instantiate the RowKeyBuilder
          + RowKeyBuilder builder = ReflectionUtils.createInstance(rowKeyBuilderClass);
          + setSaltDivisor(global, builder);
          + setPeriodDuration(global, builder);
          — End diff –

          If I had some IoC-like functionality like Flux or Spring here, then this wouldn't be a problem at all.

          Show
          githubbot ASF GitHub Bot added a comment - Github user nickwallen commented on a diff in the pull request: https://github.com/apache/metron/pull/622#discussion_r127331446 — Diff: metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/RowKeyBuilderFactory.java — @@ -0,0 +1,125 @@ +/* + * + * 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.client.stellar; + +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.lang3.ClassUtils; +import org.apache.metron.common.utils.ReflectionUtils; +import org.apache.metron.profiler.hbase.RowKeyBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.InvocationTargetException; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD; +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_PERIOD_UNITS; +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_ROW_KEY_BUILDER; +import static org.apache.metron.profiler.client.stellar.ProfilerConfig.PROFILER_SALT_DIVISOR; + +/** + * A Factory class that can create a RowKeyBuilder based on global property values. + */ +public class RowKeyBuilderFactory { + + private static final Logger LOG = LoggerFactory.getLogger(RowKeyBuilderFactory.class); + + /** + * Create a RowKeyBuilder. + * @param global The global properties. + * @return A RowKeyBuilder instantiated using the global property values. + */ + public static RowKeyBuilder create(Map<String, Object> global) { + String rowKeyBuilderClass = PROFILER_ROW_KEY_BUILDER.get(global, String.class); + LOG.debug("profiler client: {}={}", PROFILER_ROW_KEY_BUILDER, rowKeyBuilderClass); + + // instantiate the RowKeyBuilder + RowKeyBuilder builder = ReflectionUtils.createInstance(rowKeyBuilderClass); + setSaltDivisor(global, builder); + setPeriodDuration(global, builder); — End diff – If I had some IoC-like functionality like Flux or Spring here, then this wouldn't be a problem at all.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user mattf-horton commented on the issue:

          https://github.com/apache/metron/pull/622

          Your proposal has the advantage of making data in HBase self-identifying (if one has the key), which I always like. However, it's a large change and induces yet more complexity. There's an alternative I've been noodling occasionally, which I put forward here for consideration:

          Create a Profile Audit Log table in HBase. Every time a Profiler is configured, started, or stopped, make one entry in the audit log. The idea is to be able to answer exactly the kinds of questions posed in METRON-450, so the records should include things like the configuration, the first and last timestamps, and perhaps the key builder parameters. This would prevent historical profiles from being "lost" because the would-be querier doesn't have access to the exact config parameters used to write the profile.

          For the sake of housekeeping, one might do a scan, daily and/or at system restart, to assure that (a) the set Profiles with a "start" but not an "end" recorded in the audit log, and (b) the set of currently running Profiles, are actually consistent, and record "inferred end" entries in the audit log for orphans found.

          This solution is somewhat backward-applicable to existing Profile data; I think there are brute-force ways to scan the existing HBase tables and infer audit log entries, especially if historical configuration data is still available. We could write such a scanner.

          Show
          githubbot ASF GitHub Bot added a comment - Github user mattf-horton commented on the issue: https://github.com/apache/metron/pull/622 Your proposal has the advantage of making data in HBase self-identifying (if one has the key), which I always like. However, it's a large change and induces yet more complexity. There's an alternative I've been noodling occasionally, which I put forward here for consideration: Create a Profile Audit Log table in HBase. Every time a Profiler is configured, started, or stopped, make one entry in the audit log. The idea is to be able to answer exactly the kinds of questions posed in METRON-450 , so the records should include things like the configuration, the first and last timestamps, and perhaps the key builder parameters. This would prevent historical profiles from being "lost" because the would-be querier doesn't have access to the exact config parameters used to write the profile. For the sake of housekeeping, one might do a scan, daily and/or at system restart, to assure that (a) the set Profiles with a "start" but not an "end" recorded in the audit log, and (b) the set of currently running Profiles, are actually consistent, and record "inferred end" entries in the audit log for orphans found. This solution is somewhat backward-applicable to existing Profile data; I think there are brute-force ways to scan the existing HBase tables and infer audit log entries, especially if historical configuration data is still available. We could write such a scanner.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nickwallen commented on the issue:

          https://github.com/apache/metron/pull/622

          > Your proposal has the advantage of making data in HBase self-identifying (if one has the key), which I always like. However, it's a large change and induces yet more complexity

          What do you find unnecessarily complex here? The code base was already designed to accept different row key implementations. So this change involves the following.

          1. The new decodable row key
          2. Profiler client logic to instantiate row key builders
          3. Profiler client logic to pass parameters to the instantiated row key builders

          I would agree that I think item 3 is unnecessarily complex. That's where I wanted feedback. I think just passing parameters through an interface method would simplify this a lot.

          Show
          githubbot ASF GitHub Bot added a comment - Github user nickwallen commented on the issue: https://github.com/apache/metron/pull/622 > Your proposal has the advantage of making data in HBase self-identifying (if one has the key), which I always like. However, it's a large change and induces yet more complexity What do you find unnecessarily complex here? The code base was already designed to accept different row key implementations. So this change involves the following. 1. The new decodable row key 2. Profiler client logic to instantiate row key builders 3. Profiler client logic to pass parameters to the instantiated row key builders I would agree that I think item 3 is unnecessarily complex. That's where I wanted feedback. I think just passing parameters through an interface method would simplify this a lot.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nickwallen commented on the issue:

          https://github.com/apache/metron/pull/622

          I also think this row key implementation would be very helpful (if not necessary) if we want to implement Profiler Client APIs in languages that aren't JVM based. For example, the magic number can help identify byte-order differences, the version number helps us version changes over time, and the size fields allow us to reliably parse each value from the row key.

          Show
          githubbot ASF GitHub Bot added a comment - Github user nickwallen commented on the issue: https://github.com/apache/metron/pull/622 I also think this row key implementation would be very helpful (if not necessary) if we want to implement Profiler Client APIs in languages that aren't JVM based. For example, the magic number can help identify byte-order differences, the version number helps us version changes over time, and the size fields allow us to reliably parse each value from the row key.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nickwallen commented on the issue:

          https://github.com/apache/metron/pull/622

          > Create a Profile Audit Log table in HBase

          This is an interesting idea, Matt. I like it. Along these same lines I was thinking of a table of contents. I think your audit log idea is one way to implement a table of contents.

          I have looked at a TSDB implementation backed by HBase, OpenTSDB, and they use a table of contents approach. The ToC records metadata about the time series data that is stored.

          But I don't think these ideas are mutually exclusive with a decodable row key. The decodable row key would allow us to rebuild the ToC should it become corrupted or lost.

          Are you thinking that a decodable row key is not needed at all?

          Show
          githubbot ASF GitHub Bot added a comment - Github user nickwallen commented on the issue: https://github.com/apache/metron/pull/622 > Create a Profile Audit Log table in HBase This is an interesting idea, Matt. I like it. Along these same lines I was thinking of a table of contents. I think your audit log idea is one way to implement a table of contents. I have looked at a TSDB implementation backed by HBase, OpenTSDB, and they use a table of contents approach. The ToC records metadata about the time series data that is stored. But I don't think these ideas are mutually exclusive with a decodable row key. The decodable row key would allow us to rebuild the ToC should it become corrupted or lost. Are you thinking that a decodable row key is not needed at all?
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user mattf-horton commented on the issue:

          https://github.com/apache/metron/pull/622

          Hi @nickwallen ,

          • I didn't say "unnecessarily complex", I just said "adds complexity". If we are to have a decodable row key, then something like this would be necessary. The point of my comments on this is to shift to a top-down perspective:
          • The requirements you're trying to address are, I think, to be able to query metadata about existing Profiles, for multiple reasons including to not have old Profiles become inaccessible due to loss of metadata needed for Profile queries.
          • I think a ToC is a better way to do that than a decodable rowkey. It localizes the metadata instead of having to do a full scan and reason about all the rowkeys for every metadata query. I proposed the Profile audit log as a very simple way to implement a ToC, and thanks for saying that better than I did.
          • I'm not against doing a more decodable row key, it just in my mind is not the simplest nor best solution to the evident requirement. But it does constitute an architectural improvement.
          • As I briefly mentioned, I don't think our current row key is totally opaque, it just needs a brute-force approach to figure out. Not suitable for interactive queries, but would be acceptable for a one-time pass to build (or re-build) the ToC.
          Show
          githubbot ASF GitHub Bot added a comment - Github user mattf-horton commented on the issue: https://github.com/apache/metron/pull/622 Hi @nickwallen , I didn't say "unnecessarily complex", I just said "adds complexity". If we are to have a decodable row key, then something like this would be necessary. The point of my comments on this is to shift to a top-down perspective: The requirements you're trying to address are, I think, to be able to query metadata about existing Profiles, for multiple reasons including to not have old Profiles become inaccessible due to loss of metadata needed for Profile queries. I think a ToC is a better way to do that than a decodable rowkey. It localizes the metadata instead of having to do a full scan and reason about all the rowkeys for every metadata query. I proposed the Profile audit log as a very simple way to implement a ToC, and thanks for saying that better than I did. I'm not against doing a more decodable row key, it just in my mind is not the simplest nor best solution to the evident requirement. But it does constitute an architectural improvement. As I briefly mentioned, I don't think our current row key is totally opaque, it just needs a brute-force approach to figure out. Not suitable for interactive queries, but would be acceptable for a one-time pass to build (or re-build) the ToC.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nickwallen commented on the issue:

          https://github.com/apache/metron/pull/622

          > I don't think our current row key is totally opaque, it just needs a brute-force approach to figure out. Not suitable for interactive queries, but would be acceptable for a one-time pass to build (or re-build) the ToC.

          For reference, here is what the existing row key looks-like.

          salt (16B) + profile name + entity name + groups + time (8B)

          How would you decode it? The salt and the time components have known lengths; 16B and 8B respectively. Other than those two components, I don't know how to distinguish the profile name, entity or groups. I can only decode the row key if I already know either the profile name or the entity, which defeats the advantages of being able to decode it.

          Show
          githubbot ASF GitHub Bot added a comment - Github user nickwallen commented on the issue: https://github.com/apache/metron/pull/622 > I don't think our current row key is totally opaque, it just needs a brute-force approach to figure out. Not suitable for interactive queries, but would be acceptable for a one-time pass to build (or re-build) the ToC. For reference, here is what the existing row key looks-like. salt (16B) + profile name + entity name + groups + time (8B) How would you decode it? The salt and the time components have known lengths; 16B and 8B respectively. Other than those two components, I don't know how to distinguish the profile name, entity or groups. I can only decode the row key if I already know either the profile name or the entity, which defeats the advantages of being able to decode it.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user mattf-horton commented on the issue:

          https://github.com/apache/metron/pull/622

          Let me take a look at this more deeply.

          Show
          githubbot ASF GitHub Bot added a comment - Github user mattf-horton commented on the issue: https://github.com/apache/metron/pull/622 Let me take a look at this more deeply.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user cestella commented on the issue:

          https://github.com/apache/metron/pull/622

          So, in my mind the feature here is the enablement of batch analytics on the profiles. To that end, I'm in general in favor of a decodable row key. I think that the question really isn't a ToC or a decodable rowkey. I think, rather, we will want both. The two will follow different access patterns. A decodable rowkey sans ToC will be suitable only for full table scan-style access. A ToC would enable to slice or dice by profile/entity/etc.

          That being said, a ToC without a decodable rowkey is substantially less nice. Without being able to decode the rowkey, we will not be able to regenerate the ToC to provide alternative indexing. I see this as a first step to enable a broader discussion on just what kind of access semantics beyond Get/Put we want to place on the profiles.

          All that to say, I'm in favor of the effort. I worry at the impact going forward to existing profiles, though. From the point where we do this, we will create a fork whereby new profiles and old profiles diverge. I think we need to discuss the migration story more explicitly and see if it is plausible to create a migration tool that is fuzzy (i.e. will look at the existing profiles and try to pick them apart).

          I'd be ok for that work to be a follow-on, but I would want the plan to be very explicit and I would be -1 for a release until it's in.

          Show
          githubbot ASF GitHub Bot added a comment - Github user cestella commented on the issue: https://github.com/apache/metron/pull/622 So, in my mind the feature here is the enablement of batch analytics on the profiles. To that end, I'm in general in favor of a decodable row key. I think that the question really isn't a ToC or a decodable rowkey. I think, rather, we will want both. The two will follow different access patterns. A decodable rowkey sans ToC will be suitable only for full table scan-style access. A ToC would enable to slice or dice by profile/entity/etc. That being said, a ToC without a decodable rowkey is substantially less nice. Without being able to decode the rowkey, we will not be able to regenerate the ToC to provide alternative indexing. I see this as a first step to enable a broader discussion on just what kind of access semantics beyond Get/Put we want to place on the profiles. All that to say, I'm in favor of the effort. I worry at the impact going forward to existing profiles, though. From the point where we do this, we will create a fork whereby new profiles and old profiles diverge. I think we need to discuss the migration story more explicitly and see if it is plausible to create a migration tool that is fuzzy (i.e. will look at the existing profiles and try to pick them apart). I'd be ok for that work to be a follow-on, but I would want the plan to be very explicit and I would be -1 for a release until it's in.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user cestella commented on the issue:

          https://github.com/apache/metron/pull/622

          Also, while we're in here, is there a strong reason why the prefixed hash is so large? It's just there for uniformity of distribution, correct? I'd propose a non-cryptographic hash for this purpose like Murmur.

          Show
          githubbot ASF GitHub Bot added a comment - Github user cestella commented on the issue: https://github.com/apache/metron/pull/622 Also, while we're in here, is there a strong reason why the prefixed hash is so large? It's just there for uniformity of distribution, correct? I'd propose a non-cryptographic hash for this purpose like Murmur.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user cestella commented on the issue:

          https://github.com/apache/metron/pull/622

          I want to point out that I am also in favor of an audit log for the profiler, but I don't think it's a complete solution for the batch analytics use-case.

          Show
          githubbot ASF GitHub Bot added a comment - Github user cestella commented on the issue: https://github.com/apache/metron/pull/622 I want to point out that I am also in favor of an audit log for the profiler, but I don't think it's a complete solution for the batch analytics use-case.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user mattf-horton commented on a diff in the pull request:

          https://github.com/apache/metron/pull/622#discussion_r128650596

          — Diff: metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/hbase/SaltyRowKeyBuilder.java —
          @@ -81,20 +99,19 @@ public SaltyRowKeyBuilder(int saltDivisor, long duration, TimeUnit units) {

          • @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 start, long end) {
            + public List<byte[]> encode(String profile, String entity, List<Object> groups, long start, long end) {
            // be forgiving of out-of-order start and end times; order is critical to this algorithm
            end = Math.max(start, end);
            start = Math.min(start, end);
              • End diff –

          Heh, this has been in the code for a long time, but isn't this a bug? If it starts out in the wrong order, say end is 1 and start is 5, won't this pair of statements result in both end and start being equal to the larger, ie 5 ? We need an intermediate variable for a binary swap!

          Show
          githubbot ASF GitHub Bot added a comment - Github user mattf-horton commented on a diff in the pull request: https://github.com/apache/metron/pull/622#discussion_r128650596 — Diff: metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/hbase/SaltyRowKeyBuilder.java — @@ -81,20 +99,19 @@ public SaltyRowKeyBuilder(int saltDivisor, long duration, TimeUnit units) { @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 start, long end) { + public List<byte[]> encode(String profile, String entity, List<Object> groups, long start, long end) { // be forgiving of out-of-order start and end times; order is critical to this algorithm end = Math.max(start, end); start = Math.min(start, end); End diff – Heh, this has been in the code for a long time, but isn't this a bug? If it starts out in the wrong order, say end is 1 and start is 5, won't this pair of statements result in both end and start being equal to the larger, ie 5 ? We need an intermediate variable for a binary swap!
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user mattf-horton commented on the issue:

          https://github.com/apache/metron/pull/622

          Here's what I've got on decoding old rowkeys:
          https://gist.github.com/mattf-horton/8e685e373b1a3fa6aeec8ef8828be096

          The format of the keys is
          `salt (4B) + profile name + entity name + groupvalues + period (8B)`
          with most of it (all but the salt and period number) in the clear as human-readable strings.

          Deducing periodDuration has a nice arithmetic answer, I think.
          The NLP issues are of course harder. Enjoy the read, it's only two pages.

          Show
          githubbot ASF GitHub Bot added a comment - Github user mattf-horton commented on the issue: https://github.com/apache/metron/pull/622 Here's what I've got on decoding old rowkeys: https://gist.github.com/mattf-horton/8e685e373b1a3fa6aeec8ef8828be096 The format of the keys is `salt (4B) + profile name + entity name + groupvalues + period (8B)` with most of it (all but the salt and period number) in the clear as human-readable strings. Deducing periodDuration has a nice arithmetic answer, I think. The NLP issues are of course harder. Enjoy the read, it's only two pages.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user mattf-horton commented on the issue:

          https://github.com/apache/metron/pull/622

          And btw, since there is no easily expressed algorithm for the NLP part of the problem, I'm +1 on doing both a decodable rowkey and a ToC. For the existing profiles that @cestella expressed concern about, I would point out that as long as one DOES have the Profile specs still lying around, it's actually easy to re-write the old Profiles into new format with decodable rowkeys. That is a very modest-sized program, the main problem being noticing and dealing with duplicate titled Profiles with different periodDurations. But the info I pointed out in the paper helps sufficiently, I think.

          Show
          githubbot ASF GitHub Bot added a comment - Github user mattf-horton commented on the issue: https://github.com/apache/metron/pull/622 And btw, since there is no easily expressed algorithm for the NLP part of the problem, I'm +1 on doing both a decodable rowkey and a ToC. For the existing profiles that @cestella expressed concern about, I would point out that as long as one DOES have the Profile specs still lying around, it's actually easy to re-write the old Profiles into new format with decodable rowkeys. That is a very modest-sized program, the main problem being noticing and dealing with duplicate titled Profiles with different periodDurations. But the info I pointed out in the paper helps sufficiently, I think.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user cestella commented on the issue:

          https://github.com/apache/metron/pull/622

          I would agree that it's easy to rewrite the old profiles in the new decodable format IF we can read the old profile keys and pull out their info (even fuzzily).

          Show
          githubbot ASF GitHub Bot added a comment - Github user cestella commented on the issue: https://github.com/apache/metron/pull/622 I would agree that it's easy to rewrite the old profiles in the new decodable format IF we can read the old profile keys and pull out their info (even fuzzily).

            People

            • Assignee:
              nickwallen Nick Allen
              Reporter:
              nickwallen Nick Allen
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Development