You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metron.apache.org by cestella <gi...@git.apache.org> on 2018/03/08 16:28:39 UTC

[GitHub] metron pull request #958: METRON-1483: In performance evaluation, generating...

GitHub user cestella opened a pull request:

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

    METRON-1483: In performance evaluation, generating synthetic load and monitoring the write throughput of our kafka-to-kafka topologies has required a lot of custom scripting.  We should have a tool that could do the following:  Take a file representing a message template and generate synthetic load at a given events per second Monitor the kafka offsets of a topic and report throughput numbers in events per second

    ## Contributor Comments
    In performance evaluation, generating synthetic load and monitoring the write throughput of our kafka-to-kafka topologies has required a lot of custom scripting.  We should have a tool that could do the following:
    
    * Take a file representing a message template and generate synthetic load at a given events per second
    * Monitor the kafka offsets of a topic and report throughput numbers in events per second
    
    Currently pending:
    * Test plan pending
    * Documentation
    
    ## Pull Request Checklist
    
    Thank you for submitting a contribution to Apache Metron.  
    Please refer to our [Development Guidelines](https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61332235) for the complete guide to follow for contributions.  
    Please refer also to our [Build Verification Guidelines](https://cwiki.apache.org/confluence/display/METRON/Verifying+Builds?show-miniview) for complete smoke testing guides.  
    
    
    In order to streamline the review of the contribution we ask you follow these guidelines and ask you to double check the following:
    
    ### For all changes:
    - [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)?
    
    
    ### For code changes:
    - [x] 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 metron folder via:
      ```
      mvn -q clean integration-test install && dev-utilities/build-utils/verify_licenses.sh 
      ```
    
    - [x] Have you written or updated unit tests and or integration tests to verify your changes?
    - [x] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
    - [x] Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent?
    
    ### For documentation related changes:
    - [ ] Have you ensured that format looks appropriate for the output in which it is rendered by building and verifying the site-book? If not then run the following commands and the verify changes via `site-book/target/site/index.html`:
    
      ```
      cd site-book
      mvn site
      ```
    
    #### Note:
    Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
    It is also recommended that [travis-ci](https://travis-ci.org) is set up for your personal repository such that your branches are built there before submitting a pull request.


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

    $ git pull https://github.com/cestella/incubator-metron perf_tool

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

    https://github.com/apache/metron/pull/958.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 #958
    
----
commit 8ba8c57576ed318d1ff3f69cda1dc9020d62352a
Author: cstella <ce...@...>
Date:   2018-03-08T00:03:33Z

    Build load testing tool

commit 638086f2f30cfe543b624721c1fb467062571eab
Author: cstella <ce...@...>
Date:   2018-03-08T15:31:55Z

    refactoring monitoring to be more sensible.

commit 55be01de033d0ea6b489930cb97fefcca80efdb5
Author: cstella <ce...@...>
Date:   2018-03-08T16:20:52Z

    Added summarization

----


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174186641
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/monitor/writers/Writer.java ---
    @@ -0,0 +1,91 @@
    +/**
    + * 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.performance.load.monitor.writers;
    +
    +import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
    +import org.apache.metron.performance.load.monitor.AbstractMonitor;
    +import org.apache.metron.performance.load.monitor.Results;
    +
    +import java.util.ArrayList;
    +import java.util.Date;
    +import java.util.LinkedList;
    +import java.util.List;
    +import java.util.Optional;
    +import java.util.function.Consumer;
    +
    +public class Writer {
    +
    +  private int summaryLookback;
    +  private List<LinkedList<Double>> summaries = new ArrayList<>();
    +  private List<Consumer<Writable>> writers;
    +  private List<AbstractMonitor> monitors;
    +
    +  public Writer(List<AbstractMonitor> monitors, int summaryLookback, List<Consumer<Writable>> writers) {
    +    this.summaryLookback = summaryLookback;
    +    this.writers = writers;
    +    this.monitors = monitors;
    +    for(AbstractMonitor m : monitors) {
    +      this.summaries.add(new LinkedList<>());
    +    }
    +  }
    +
    +  public void writeAll() {
    +    int i = 0;
    +    Date dateOf = new Date();
    +    List<Results> results = new ArrayList<>();
    +    for(AbstractMonitor m : monitors) {
    +      Long eps = m.get();
    +      if(eps != null) {
    +        if (summaryLookback > 0) {
    +          LinkedList<Double> summary = summaries.get(i);
    +          addToLookback(eps == null ? Double.NaN : eps.doubleValue(), summary);
    --- End diff --
    
    done


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173929511
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/monitor/writers/Writer.java ---
    @@ -0,0 +1,91 @@
    +/**
    + * 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.performance.load.monitor.writers;
    +
    +import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
    +import org.apache.metron.performance.load.monitor.AbstractMonitor;
    +import org.apache.metron.performance.load.monitor.Results;
    +
    +import java.util.ArrayList;
    +import java.util.Date;
    +import java.util.LinkedList;
    +import java.util.List;
    +import java.util.Optional;
    +import java.util.function.Consumer;
    +
    +public class Writer {
    +
    +  private int summaryLookback;
    +  private List<LinkedList<Double>> summaries = new ArrayList<>();
    +  private List<Consumer<Writable>> writers;
    +  private List<AbstractMonitor> monitors;
    +
    +  public Writer(List<AbstractMonitor> monitors, int summaryLookback, List<Consumer<Writable>> writers) {
    +    this.summaryLookback = summaryLookback;
    +    this.writers = writers;
    +    this.monitors = monitors;
    +    for(AbstractMonitor m : monitors) {
    +      this.summaries.add(new LinkedList<>());
    +    }
    +  }
    +
    +  public void writeAll() {
    +    int i = 0;
    +    Date dateOf = new Date();
    +    List<Results> results = new ArrayList<>();
    +    for(AbstractMonitor m : monitors) {
    +      Long eps = m.get();
    +      if(eps != null) {
    +        if (summaryLookback > 0) {
    +          LinkedList<Double> summary = summaries.get(i);
    +          addToLookback(eps == null ? Double.NaN : eps.doubleValue(), summary);
    +          results.add(new Results(m.format(), m.name(), eps, Optional.of(getStats(summary))));
    +        }
    +        else {
    +          results.add(new Results(m.format(),m.name(), eps, Optional.empty()));
    +        }
    +      }
    +      else {
    --- End diff --
    
    Since the two else's are the same, I think this should simplify down to (with the above change):
    ```
          if (eps != null && summaryLookback > 0) {
            LinkedList<Double> summary = summaries.get(i);
            addToLookback(eps.doubleValue(), summary);
            results.add(new Results(m.format(), m.name(), eps, Optional.of(getStats(summary))));
          } else {
            results.add(new Results(m.format(), m.name(), eps, Optional.empty()));
          }
    ```


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173924485
  
    --- Diff: metron-contrib/metron-performance/src/test/java/org/apache/metron/performance/load/SendToKafkaTest.java ---
    @@ -0,0 +1,49 @@
    +/**
    + * 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.performance.load;
    +
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.ForkJoinPool;
    +import java.util.concurrent.Future;
    +import java.util.concurrent.atomic.AtomicLong;
    +
    +public class SendToKafkaTest {
    +
    +  @Test
    +  public void testWritesCorrectNumber() throws InterruptedException {
    --- End diff --
    
    InterruptedException isn't thrown here, is it?


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174478516
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/SendToKafka.java ---
    @@ -0,0 +1,107 @@
    +/**
    + * 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.performance.load;
    +
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.apache.kafka.clients.producer.ProducerRecord;
    +
    +import java.util.ArrayList;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.TimerTask;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Future;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Supplier;
    +
    +public class SendToKafka extends TimerTask {
    --- End diff --
    
    Ah, so if I'm following you, making the `ThreadLocal<KafkaProducer>` into `ThreadLocal<KafkaProducer<String, String>>` would solve the issue, correct?  I'd prefer to not change to`SendToKafka<K, V>` because it implies that we might be sending something other than String in this implementation.  We would not because the message generator sends Strings and I'd prefer to not generalize that.


---

[GitHub] metron issue #958: METRON-1483: Create a tool to monitor performance of the ...

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

    https://github.com/apache/metron/pull/958
  
    # Testing Plan:
    We presume
    * `ZOOKEEPER` is an environment variable set to the zk quorum (e.g. `node1:2181`)
    * `BROKER` is an environment variable set to the broker (e.g. `node1:6667`)
    
    ## Unbiased Generation
    
    In order to test this, we will:
    1. create a new topic
    ```
    # Create dummy_12_unbiased with 12 partitions
    /usr/hdp/current/kafka-broker/bin/kafka-topics.sh --zookeeper $ZOOKEEPER --create --topic dummy_12_unbiased --partitions 12 --replication-factor 1
    ```
    2. Create some dummy data to send into kafka
    ```
    # Generate some templates of dummy data that look like CSV in ~/dummy.templates
    # With a number, a string, a GUID and the timestamp
    for i in $(seq 1 100);do echo "$i,foo,\$METRON_GUID,\$METRON_TS";done > ~/dummy.templates
    ```
    3. Write into that topic from a set of templates at a specified rate
    ```
    # Write out 1000 messages per second to dummy_12_unbiased
    # Monitor dummy_12_unbiased
    # Each message is drawn from the set of templates in step 2.
    # Stop after 60 seconds and report how much you've written
    $METRON_HOME/bin/load_tool.sh -p 5 -ot dummy_12_unbiased -mt dummy_12_unbiased -t ~/dummy.template -eps 1000 -z $ZOOKEEPER -tl 60000
    ```
      * It should indicate that it generated something like 60k messages
    4. Measure if the messages generated roughly match the requested rate.
    ```
    # You will have to ctrl-c this in a few seconds
    /usr/hdp/current/kafka-broker/bin/kafka-console-consumer.sh --bootstrap-server node1:6667 --topic dummy_12_topic --from-beginning | wc -l
    ```
      * It should output something like `Processed a total of 60400 messages`, which would be about 1000 messages per second.



---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173933259
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/sampler/UnbiasedSampler.java ---
    @@ -0,0 +1,28 @@
    +/**
    + * 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.performance.sampler;
    +
    +import java.util.Random;
    +
    +public class UnbiasedSampler implements Sampler {
    +
    +  @Override
    +  public int sample(Random rng, int limit) {
    +    return rng.nextInt(limit);
    --- End diff --
    
    If the templates file is empty, there will be no bounds here, and this will start puking exceptions out.


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173918976
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/LoadGenerator.java ---
    @@ -0,0 +1,165 @@
    +/**
    + * 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.performance.load;
    +
    +
    +import com.google.common.base.Joiner;
    +import org.apache.commons.cli.CommandLine;
    +import org.apache.commons.cli.PosixParser;
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.apache.metron.common.utils.KafkaUtils;
    +import org.apache.metron.performance.load.monitor.AbstractMonitor;
    +import org.apache.metron.performance.load.monitor.EPSGeneratedMonitor;
    +import org.apache.metron.performance.load.monitor.EPSThroughputWrittenMonitor;
    +import org.apache.metron.performance.load.monitor.MonitorTask;
    +import org.apache.metron.performance.load.monitor.writers.CSVWriter;
    +import org.apache.metron.performance.load.monitor.writers.ConsoleWriter;
    +import org.apache.metron.performance.load.monitor.writers.Writable;
    +import org.apache.metron.performance.load.monitor.writers.Writer;
    +import org.apache.metron.performance.sampler.BiasedSampler;
    +import org.apache.metron.performance.sampler.Sampler;
    +import org.apache.metron.performance.sampler.UnbiasedSampler;
    +
    +import java.io.File;
    +import java.util.ArrayList;
    +import java.util.EnumMap;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Optional;
    +import java.util.Timer;
    +import java.util.TimerTask;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Executors;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Consumer;
    +
    +public class LoadGenerator
    +{
    +  public static String CONSUMER_GROUP = "load.group";
    +  public static long SEND_PERIOD_MS = 100;
    +  public static long MONITOR_PERIOD_MS = 1000*10;
    +  private static ExecutorService pool;
    +  private static ThreadLocal<KafkaProducer> kafkaProducer;
    +  public static AtomicLong numSent = new AtomicLong(0);
    +
    +  public static void main( String[] args ) throws Exception {
    +    CommandLine cli = LoadOptions.parse(new PosixParser(), args);
    +    EnumMap<LoadOptions, Optional<Object>> evaluatedArgs = LoadOptions.createConfig(cli);
    +    Map<String, Object> kafkaConfig = new HashMap<>();
    +    kafkaConfig.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    +    kafkaConfig.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    +    kafkaConfig.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
    +    kafkaConfig.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
    +    if(LoadOptions.ZK.has(cli)) {
    +      String zkQuorum = (String) evaluatedArgs.get(LoadOptions.ZK).get();
    +      kafkaConfig.put("bootstrap.servers", Joiner.on(",").join(KafkaUtils.INSTANCE.getBrokersFromZookeeper(zkQuorum)));
    +    }
    +    String groupId = evaluatedArgs.get(LoadOptions.CONSUMER_GROUP).get().toString();
    +    System.out.println("Consumer Group: " + groupId);
    +    kafkaConfig.put("group.id", groupId);
    --- End diff --
    
    Same as before: ConsumerGroup.GROUP_ID_CONFIG


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173917605
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/LoadGenerator.java ---
    @@ -0,0 +1,165 @@
    +/**
    + * 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.performance.load;
    +
    +
    +import com.google.common.base.Joiner;
    +import org.apache.commons.cli.CommandLine;
    +import org.apache.commons.cli.PosixParser;
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.apache.metron.common.utils.KafkaUtils;
    +import org.apache.metron.performance.load.monitor.AbstractMonitor;
    +import org.apache.metron.performance.load.monitor.EPSGeneratedMonitor;
    +import org.apache.metron.performance.load.monitor.EPSThroughputWrittenMonitor;
    +import org.apache.metron.performance.load.monitor.MonitorTask;
    +import org.apache.metron.performance.load.monitor.writers.CSVWriter;
    +import org.apache.metron.performance.load.monitor.writers.ConsoleWriter;
    +import org.apache.metron.performance.load.monitor.writers.Writable;
    +import org.apache.metron.performance.load.monitor.writers.Writer;
    +import org.apache.metron.performance.sampler.BiasedSampler;
    +import org.apache.metron.performance.sampler.Sampler;
    +import org.apache.metron.performance.sampler.UnbiasedSampler;
    +
    +import java.io.File;
    +import java.util.ArrayList;
    +import java.util.EnumMap;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Optional;
    +import java.util.Timer;
    +import java.util.TimerTask;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Executors;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Consumer;
    +
    +public class LoadGenerator
    +{
    +  public static String CONSUMER_GROUP = "load.group";
    --- End diff --
    
    Should this maybe be "metron.load.group" by default?  This is a little generic, and even though it's not terribly likely, could collide with someone else on the Kafka cluster.


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174186700
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/monitor/writers/Writer.java ---
    @@ -0,0 +1,91 @@
    +/**
    + * 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.performance.load.monitor.writers;
    +
    +import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
    +import org.apache.metron.performance.load.monitor.AbstractMonitor;
    +import org.apache.metron.performance.load.monitor.Results;
    +
    +import java.util.ArrayList;
    +import java.util.Date;
    +import java.util.LinkedList;
    +import java.util.List;
    +import java.util.Optional;
    +import java.util.function.Consumer;
    +
    +public class Writer {
    +
    +  private int summaryLookback;
    +  private List<LinkedList<Double>> summaries = new ArrayList<>();
    +  private List<Consumer<Writable>> writers;
    +  private List<AbstractMonitor> monitors;
    +
    +  public Writer(List<AbstractMonitor> monitors, int summaryLookback, List<Consumer<Writable>> writers) {
    +    this.summaryLookback = summaryLookback;
    +    this.writers = writers;
    +    this.monitors = monitors;
    +    for(AbstractMonitor m : monitors) {
    +      this.summaries.add(new LinkedList<>());
    +    }
    +  }
    +
    +  public void writeAll() {
    +    int i = 0;
    +    Date dateOf = new Date();
    +    List<Results> results = new ArrayList<>();
    +    for(AbstractMonitor m : monitors) {
    +      Long eps = m.get();
    +      if(eps != null) {
    +        if (summaryLookback > 0) {
    +          LinkedList<Double> summary = summaries.get(i);
    +          addToLookback(eps == null ? Double.NaN : eps.doubleValue(), summary);
    +          results.add(new Results(m.format(), m.name(), eps, Optional.of(getStats(summary))));
    +        }
    +        else {
    +          results.add(new Results(m.format(),m.name(), eps, Optional.empty()));
    +        }
    +      }
    +      else {
    --- End diff --
    
    done


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174488230
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/SendToKafka.java ---
    @@ -0,0 +1,107 @@
    +/**
    + * 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.performance.load;
    +
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.apache.kafka.clients.producer.ProducerRecord;
    +
    +import java.util.ArrayList;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.TimerTask;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Future;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Supplier;
    +
    +public class SendToKafka extends TimerTask {
    --- End diff --
    
    Yeah, that's a fair point. Yeah, I'd just go ahead with `ThreadLocal<KafkaProducer<String, String>>` and make the arguments to the couple functions that take it `KafkaProducer<String, String>` and I'm good.


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174186275
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/LoadGenerator.java ---
    @@ -0,0 +1,165 @@
    +/**
    + * 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.performance.load;
    +
    +
    +import com.google.common.base.Joiner;
    +import org.apache.commons.cli.CommandLine;
    +import org.apache.commons.cli.PosixParser;
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.apache.metron.common.utils.KafkaUtils;
    +import org.apache.metron.performance.load.monitor.AbstractMonitor;
    +import org.apache.metron.performance.load.monitor.EPSGeneratedMonitor;
    +import org.apache.metron.performance.load.monitor.EPSThroughputWrittenMonitor;
    +import org.apache.metron.performance.load.monitor.MonitorTask;
    +import org.apache.metron.performance.load.monitor.writers.CSVWriter;
    +import org.apache.metron.performance.load.monitor.writers.ConsoleWriter;
    +import org.apache.metron.performance.load.monitor.writers.Writable;
    +import org.apache.metron.performance.load.monitor.writers.Writer;
    +import org.apache.metron.performance.sampler.BiasedSampler;
    +import org.apache.metron.performance.sampler.Sampler;
    +import org.apache.metron.performance.sampler.UnbiasedSampler;
    +
    +import java.io.File;
    +import java.util.ArrayList;
    +import java.util.EnumMap;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Optional;
    +import java.util.Timer;
    +import java.util.TimerTask;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Executors;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Consumer;
    +
    +public class LoadGenerator
    +{
    +  public static String CONSUMER_GROUP = "load.group";
    +  public static long SEND_PERIOD_MS = 100;
    +  public static long MONITOR_PERIOD_MS = 1000*10;
    +  private static ExecutorService pool;
    +  private static ThreadLocal<KafkaProducer> kafkaProducer;
    +  public static AtomicLong numSent = new AtomicLong(0);
    +
    +  public static void main( String[] args ) throws Exception {
    +    CommandLine cli = LoadOptions.parse(new PosixParser(), args);
    +    EnumMap<LoadOptions, Optional<Object>> evaluatedArgs = LoadOptions.createConfig(cli);
    +    Map<String, Object> kafkaConfig = new HashMap<>();
    +    kafkaConfig.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    --- End diff --
    
    done


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174186529
  
    --- Diff: metron-contrib/metron-performance/src/test/java/org/apache/metron/performance/load/SendToKafkaTest.java ---
    @@ -0,0 +1,49 @@
    +/**
    + * 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.performance.load;
    +
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.ForkJoinPool;
    +import java.util.concurrent.Future;
    +import java.util.concurrent.atomic.AtomicLong;
    +
    +public class SendToKafkaTest {
    +
    +  @Test
    +  public void testWritesCorrectNumber() throws InterruptedException {
    --- End diff --
    
    done


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173925390
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/SendToKafka.java ---
    @@ -0,0 +1,107 @@
    +/**
    + * 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.performance.load;
    +
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.apache.kafka.clients.producer.ProducerRecord;
    +
    +import java.util.ArrayList;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.TimerTask;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Future;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Supplier;
    +
    +public class SendToKafka extends TimerTask {
    --- End diff --
    
    This class feels like it should be genericized as SendToKafka<K, V> where it takes args as appropriate.  Right now this is just basically a SendToKafka<String, String>, correct?


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173936212
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/sampler/BiasedSampler.java ---
    @@ -0,0 +1,95 @@
    +/**
    + * 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.performance.sampler;
    +
    +import com.google.common.base.Splitter;
    +import com.google.common.collect.Iterables;
    +
    +import java.io.BufferedReader;
    +import java.io.File;
    +import java.io.FileReader;
    +import java.io.IOException;
    +import java.util.AbstractMap;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Random;
    +import java.util.TreeMap;
    +
    +public class BiasedSampler implements Sampler {
    +  TreeMap<Double, Map.Entry<Integer, Integer>> discreteDistribution;
    +  public BiasedSampler(List<Map.Entry<Integer, Integer>>  discreteDistribution, int max) {
    +    this.discreteDistribution = createDistribution(discreteDistribution, max);
    +  }
    +
    +  public static List<Map.Entry<Integer, Integer>> readDistribution(File distrFile) throws IOException {
    +    List<Map.Entry<Integer, Integer>> ret = new ArrayList<>();
    +    System.out.println("Using biased sampler with the following biases:");
    +    try(BufferedReader br = new BufferedReader(new FileReader(distrFile))) {
    +      int sumLeft = 0;
    +      int sumRight = 0;
    +      for(String line = null;(line = br.readLine()) != null;) {
    +        if(line.startsWith("#")) {
    +          continue;
    +        }
    +        Iterable<String> it = Splitter.on(",").split(line.trim());
    +        int left = Integer.parseInt(Iterables.getFirst(it, null));
    +        int right = Integer.parseInt(Iterables.getLast(it, null));
    +        System.out.println("\t" + left + "% of templates will comprise roughly " + right + "% of sample output");
    +        ret.add(new AbstractMap.SimpleEntry<>(left, right));
    +        sumLeft += left;
    +        sumRight += right;
    +      }
    +      if(sumLeft > 100 || sumRight > 100 ) {
    +        throw new IllegalStateException("Neither columns must sum to beyond 100.  " +
    +                "The first column is the % of templates. " +
    +                "The second column is the % of the sample that % of template occupies.");
    +      }
    +      else if(sumLeft < 100 && sumRight < 100) {
    +        int left = 100 - sumLeft;
    +        int right = 100 - sumRight;
    +        System.out.println("\t" + left + "% of templates will comprise roughly " + right + "% of sample output");
    +        ret.add(new AbstractMap.SimpleEntry<>(left, right));
    +      }
    +      return ret;
    +    }
    +  }
    +
    +  private static TreeMap<Double, Map.Entry<Integer, Integer>>
    +                 createDistribution(List<Map.Entry<Integer, Integer>>  discreteDistribution, int max) {
    +    TreeMap<Double, Map.Entry<Integer, Integer>> ret = new TreeMap<>();
    +    int from = 0;
    +    double weight = 0.0d;
    +    for(Map.Entry<Integer, Integer> kv : discreteDistribution) {
    +      double pctVals = kv.getKey()/100.0;
    +      int to = from + (int)(max*pctVals);
    +      double pctWeight = kv.getValue()/100.0;
    +      ret.put(weight, new AbstractMap.SimpleEntry<>(from, to));
    +      weight += pctWeight;
    +      from = to;
    +    }
    +    return ret;
    +  }
    +
    +  @Override
    +  public int sample(Random rng, int limit) {
    +    double weight = rng.nextDouble();
    +    Map.Entry<Integer, Integer> range = discreteDistribution.floorEntry(weight).getValue();
    +    return rng.nextInt(range.getValue() - range.getKey()) + range.getKey();
    --- End diff --
    
    Jerks like me who provide negatives or zeroes cause ugly exceptions to start showing up. because the nextInt doesn't get happy values.


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174186597
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/monitor/writers/ConsoleWriter.java ---
    @@ -0,0 +1,67 @@
    +/**
    + * 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.performance.load.monitor.writers;
    +
    +import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
    +import org.apache.metron.performance.load.monitor.Results;
    +
    +import java.text.DateFormat;
    +import java.text.SimpleDateFormat;
    +import java.util.ArrayList;
    +import java.util.Date;
    +import java.util.List;
    +import java.util.function.Consumer;
    +
    +public class ConsoleWriter implements Consumer<Writable> {
    +
    +  private String getSummary(DescriptiveStatistics stats) {
    +    return String.format("Mean: %d, Std Dev: %d", (int)stats.getMean(), (int)Math.sqrt(stats.getVariance()));
    +  }
    +
    +  @Override
    +  public void accept(Writable writable) {
    +    List<String> parts = new ArrayList<>();
    +    Date date = writable.getDate();
    +    for(Results r : writable.getResults()) {
    +      Long eps = r.getEps();
    +      if(eps != null) {
    +        String part = String.format(r.getFormat(), eps);
    +        if (r.getHistory().isPresent()) {
    +          part += " (" + getSummary(r.getHistory().get()) + ")";
    +        }
    +        parts.add(part);
    +      }
    +    }
    +    if(date != null) {
    +      DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    +      String header = dateFormat.format(date) + " - ";
    +      String emptyHeader = "";
    +      for (int i = 0; i < header.length(); ++i) {
    --- End diff --
    
    done


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174181759
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/SendToKafka.java ---
    @@ -0,0 +1,107 @@
    +/**
    + * 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.performance.load;
    +
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.apache.kafka.clients.producer.ProducerRecord;
    +
    +import java.util.ArrayList;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.TimerTask;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Future;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Supplier;
    +
    +public class SendToKafka extends TimerTask {
    --- End diff --
    
    well, I mean, I suppose it could be, but I didn't see value in it since all of our inputs currently are strings and the message generator exclusively generates strings, not other messages.  It'd be a more serious refactoring to genericize this to make the message generator pluggable.  Also, for utility code, I think I'd rather avoid prematurely generalizing it.  Let me know what you think.


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174186826
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/sampler/BiasedSampler.java ---
    @@ -0,0 +1,95 @@
    +/**
    + * 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.performance.sampler;
    +
    +import com.google.common.base.Splitter;
    +import com.google.common.collect.Iterables;
    +
    +import java.io.BufferedReader;
    +import java.io.File;
    +import java.io.FileReader;
    +import java.io.IOException;
    +import java.util.AbstractMap;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Random;
    +import java.util.TreeMap;
    +
    +public class BiasedSampler implements Sampler {
    +  TreeMap<Double, Map.Entry<Integer, Integer>> discreteDistribution;
    +  public BiasedSampler(List<Map.Entry<Integer, Integer>>  discreteDistribution, int max) {
    +    this.discreteDistribution = createDistribution(discreteDistribution, max);
    +  }
    +
    +  public static List<Map.Entry<Integer, Integer>> readDistribution(File distrFile) throws IOException {
    +    List<Map.Entry<Integer, Integer>> ret = new ArrayList<>();
    +    System.out.println("Using biased sampler with the following biases:");
    +    try(BufferedReader br = new BufferedReader(new FileReader(distrFile))) {
    +      int sumLeft = 0;
    +      int sumRight = 0;
    +      for(String line = null;(line = br.readLine()) != null;) {
    +        if(line.startsWith("#")) {
    +          continue;
    +        }
    +        Iterable<String> it = Splitter.on(",").split(line.trim());
    +        int left = Integer.parseInt(Iterables.getFirst(it, null));
    +        int right = Integer.parseInt(Iterables.getLast(it, null));
    +        System.out.println("\t" + left + "% of templates will comprise roughly " + right + "% of sample output");
    +        ret.add(new AbstractMap.SimpleEntry<>(left, right));
    +        sumLeft += left;
    +        sumRight += right;
    +      }
    +      if(sumLeft > 100 || sumRight > 100 ) {
    +        throw new IllegalStateException("Neither columns must sum to beyond 100.  " +
    +                "The first column is the % of templates. " +
    +                "The second column is the % of the sample that % of template occupies.");
    +      }
    +      else if(sumLeft < 100 && sumRight < 100) {
    +        int left = 100 - sumLeft;
    +        int right = 100 - sumRight;
    +        System.out.println("\t" + left + "% of templates will comprise roughly " + right + "% of sample output");
    +        ret.add(new AbstractMap.SimpleEntry<>(left, right));
    +      }
    +      return ret;
    +    }
    +  }
    +
    +  private static TreeMap<Double, Map.Entry<Integer, Integer>>
    +                 createDistribution(List<Map.Entry<Integer, Integer>>  discreteDistribution, int max) {
    +    TreeMap<Double, Map.Entry<Integer, Integer>> ret = new TreeMap<>();
    +    int from = 0;
    +    double weight = 0.0d;
    +    for(Map.Entry<Integer, Integer> kv : discreteDistribution) {
    +      double pctVals = kv.getKey()/100.0;
    +      int to = from + (int)(max*pctVals);
    +      double pctWeight = kv.getValue()/100.0;
    +      ret.put(weight, new AbstractMap.SimpleEntry<>(from, to));
    +      weight += pctWeight;
    +      from = to;
    +    }
    +    return ret;
    +  }
    +
    +  @Override
    +  public int sample(Random rng, int limit) {
    +    double weight = rng.nextDouble();
    +    Map.Entry<Integer, Integer> range = discreteDistribution.floorEntry(weight).getValue();
    +    return rng.nextInt(range.getValue() - range.getKey()) + range.getKey();
    --- End diff --
    
    done


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174186359
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/LoadGenerator.java ---
    @@ -0,0 +1,165 @@
    +/**
    + * 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.performance.load;
    +
    +
    +import com.google.common.base.Joiner;
    +import org.apache.commons.cli.CommandLine;
    +import org.apache.commons.cli.PosixParser;
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.apache.metron.common.utils.KafkaUtils;
    +import org.apache.metron.performance.load.monitor.AbstractMonitor;
    +import org.apache.metron.performance.load.monitor.EPSGeneratedMonitor;
    +import org.apache.metron.performance.load.monitor.EPSThroughputWrittenMonitor;
    +import org.apache.metron.performance.load.monitor.MonitorTask;
    +import org.apache.metron.performance.load.monitor.writers.CSVWriter;
    +import org.apache.metron.performance.load.monitor.writers.ConsoleWriter;
    +import org.apache.metron.performance.load.monitor.writers.Writable;
    +import org.apache.metron.performance.load.monitor.writers.Writer;
    +import org.apache.metron.performance.sampler.BiasedSampler;
    +import org.apache.metron.performance.sampler.Sampler;
    +import org.apache.metron.performance.sampler.UnbiasedSampler;
    +
    +import java.io.File;
    +import java.util.ArrayList;
    +import java.util.EnumMap;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Optional;
    +import java.util.Timer;
    +import java.util.TimerTask;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Executors;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Consumer;
    +
    +public class LoadGenerator
    +{
    +  public static String CONSUMER_GROUP = "load.group";
    +  public static long SEND_PERIOD_MS = 100;
    +  public static long MONITOR_PERIOD_MS = 1000*10;
    +  private static ExecutorService pool;
    +  private static ThreadLocal<KafkaProducer> kafkaProducer;
    +  public static AtomicLong numSent = new AtomicLong(0);
    +
    +  public static void main( String[] args ) throws Exception {
    +    CommandLine cli = LoadOptions.parse(new PosixParser(), args);
    +    EnumMap<LoadOptions, Optional<Object>> evaluatedArgs = LoadOptions.createConfig(cli);
    +    Map<String, Object> kafkaConfig = new HashMap<>();
    +    kafkaConfig.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    +    kafkaConfig.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    +    kafkaConfig.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
    +    kafkaConfig.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
    +    if(LoadOptions.ZK.has(cli)) {
    +      String zkQuorum = (String) evaluatedArgs.get(LoadOptions.ZK).get();
    +      kafkaConfig.put("bootstrap.servers", Joiner.on(",").join(KafkaUtils.INSTANCE.getBrokersFromZookeeper(zkQuorum)));
    --- End diff --
    
    done


---

[GitHub] metron issue #958: METRON-1483: Create a tool to monitor performance of the ...

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

    https://github.com/apache/metron/pull/958
  
    I'm all set, +1. Thanks for this, it's great stuff.


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174468438
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/SendToKafka.java ---
    @@ -0,0 +1,107 @@
    +/**
    + * 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.performance.load;
    +
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.apache.kafka.clients.producer.ProducerRecord;
    +
    +import java.util.ArrayList;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.TimerTask;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Future;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Supplier;
    +
    +public class SendToKafka extends TimerTask {
    --- End diff --
    
    To expand on the reasoning for just making it SendToKafka<K, V>, right now it's using raw KafkaProducer, with one exception.  Since we already know the types, we can make it KafkaProducer<String, String> in the arguments.  I think we shouldn't leave it raw, because  passing in a different KafkaProducer is going to be incorrect the exception at line 71:
    `KafkaProducer<String, String> producer = kafkaProducer.get();`.
    
    I definitely don't think making the whole thing pluggable is worth doing now but making the KafkaProducer's all <String, String> for correctness vs just making the class <K, V> is basically the same amount of effort.


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173942355
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/monitor/AbstractMonitor.java ---
    @@ -0,0 +1,49 @@
    +/**
    + * 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.performance.load.monitor;
    +
    +import java.util.Optional;
    +import java.util.function.Supplier;
    +
    +public abstract class AbstractMonitor implements Supplier<Long>, MonitorNaming {
    +  private static final double EPSILON = 1e-6;
    +  protected Optional<?> kafkaTopic;
    +  protected long timestampPrevious = 0;
    +  public AbstractMonitor(Optional<?> kafkaTopic) {
    +    this.kafkaTopic = kafkaTopic;
    +  }
    +
    +  protected abstract Long monitor(double deltaTs);
    +
    +  @Override
    +  public Long get() {
    +    long timeStarted = System.currentTimeMillis();
    --- End diff --
    
    To my knowledge, `currentTimeMillis()` is not affected by DST as it is the milliseconds since unix epoch UTC.  Cursory googling seems to hold up this assertion.  Did I miss something?


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173928769
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/monitor/writers/Writer.java ---
    @@ -0,0 +1,91 @@
    +/**
    + * 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.performance.load.monitor.writers;
    +
    +import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
    +import org.apache.metron.performance.load.monitor.AbstractMonitor;
    +import org.apache.metron.performance.load.monitor.Results;
    +
    +import java.util.ArrayList;
    +import java.util.Date;
    +import java.util.LinkedList;
    +import java.util.List;
    +import java.util.Optional;
    +import java.util.function.Consumer;
    +
    +public class Writer {
    +
    +  private int summaryLookback;
    +  private List<LinkedList<Double>> summaries = new ArrayList<>();
    +  private List<Consumer<Writable>> writers;
    +  private List<AbstractMonitor> monitors;
    +
    +  public Writer(List<AbstractMonitor> monitors, int summaryLookback, List<Consumer<Writable>> writers) {
    +    this.summaryLookback = summaryLookback;
    +    this.writers = writers;
    +    this.monitors = monitors;
    +    for(AbstractMonitor m : monitors) {
    +      this.summaries.add(new LinkedList<>());
    +    }
    +  }
    +
    +  public void writeAll() {
    +    int i = 0;
    +    Date dateOf = new Date();
    +    List<Results> results = new ArrayList<>();
    +    for(AbstractMonitor m : monitors) {
    +      Long eps = m.get();
    +      if(eps != null) {
    +        if (summaryLookback > 0) {
    +          LinkedList<Double> summary = summaries.get(i);
    +          addToLookback(eps == null ? Double.NaN : eps.doubleValue(), summary);
    --- End diff --
    
    eps is never null here, so this can be just `addToLookback(eps.doubleValue(), summary);`


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174186490
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/MessageGenerator.java ---
    @@ -0,0 +1,48 @@
    +/**
    + * 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.performance.load;
    +
    +import org.apache.metron.performance.sampler.Sampler;
    +
    +import java.util.List;
    +import java.util.Random;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Supplier;
    +
    +public class MessageGenerator implements Supplier<String> {
    +  private static ThreadLocal<Random> rng = ThreadLocal.withInitial(() -> new Random());
    +  private static AtomicLong guidOffset = new AtomicLong(0);
    +  private static String guidPrefix = "6141faf6-a8ba-4044-ab80-";
    --- End diff --
    
    done


---

[GitHub] metron issue #958: METRON-1483: Create a tool to monitor performance of the ...

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

    https://github.com/apache/metron/pull/958
  
    Moving this conversation to the top.  I believe I have refactored the KafkaProducers appropriately.  Let me know if I missed something, @justinleet 


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174186422
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/LoadOptions.java ---
    @@ -0,0 +1,504 @@
    +/**
    + * 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.performance.load;
    +
    +import com.google.common.base.Joiner;
    +import org.apache.commons.cli.*;
    +import org.apache.metron.common.utils.JSONUtils;
    +import org.apache.metron.common.utils.cli.CLIOptions;
    +import org.apache.metron.performance.sampler.BiasedSampler;
    +import org.apache.metron.stellar.common.utils.ConversionUtils;
    +import org.apache.metron.common.utils.cli.OptionHandler;
    +
    +import javax.annotation.Nullable;
    +import java.io.BufferedReader;
    +import java.io.File;
    +import java.io.FileNotFoundException;
    +import java.io.FileReader;
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import java.util.EnumMap;
    +import java.util.List;
    +import java.util.Optional;
    +
    +public enum LoadOptions implements CLIOptions<LoadOptions> {
    +  HELP(new OptionHandler<LoadOptions>() {
    +
    +    @Override
    +    public String getShortCode() {
    +      return "h";
    +    }
    +
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      return new Option(s, "help", false, "Generate Help screen");
    +    }
    +  }),
    +  ZK(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "zk_quorum", true, "zookeeper quorum");
    +      o.setArgName("QUORUM");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(option.has(cli)) {
    +        return Optional.ofNullable(option.get(cli));
    +      }
    +      else {
    +        return Optional.empty();
    +      }
    +    }
    +
    +    @Override
    +    public String getShortCode() {
    +      return "z";
    +    }
    +  }),
    +  CONSUMER_GROUP(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "consumer_group", true, "Consumer Group.  The default is " + LoadGenerator.CONSUMER_GROUP);
    +      o.setArgName("GROUP_ID");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(option.has(cli)) {
    +        return Optional.ofNullable(option.get(cli));
    +      }
    +      else {
    +        return Optional.of(LoadGenerator.CONSUMER_GROUP);
    +      }
    +    }
    +
    +    @Override
    +    public String getShortCode() {
    +      return "cg";
    +    }
    +  }),
    +  BIASED_SAMPLE(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "sample_bias", true, "The discrete distribution to bias the sampling. " +
    +              "This is a CSV of 2 columns.  The first column is the % of the templates " +
    +              "and the 2nd column is the probability (0-100) that it's chosen.  For instance:\n" +
    +              "  20,80\n" +
    +              "  80,20\n" +
    +              "implies that 20% of the templates will comprise 80% of the output and the remaining 80% of the templates will comprise 20% of the output.");
    +      o.setArgName("BIAS_FILE");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(!option.has(cli)) {
    +        return Optional.empty();
    +      }
    +      File discreteDistributionFile  = new File(option.get(cli));
    +      if(discreteDistributionFile.exists()) {
    +        try {
    +
    +          return Optional.ofNullable(BiasedSampler.readDistribution(discreteDistributionFile));
    +        } catch (FileNotFoundException e) {
    +          throw new IllegalStateException("Unable to read distribution file: " + option.get(cli), e);
    +        } catch (IOException e) {
    --- End diff --
    
    done


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

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

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


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174186723
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/sampler/BiasedSampler.java ---
    @@ -0,0 +1,95 @@
    +/**
    + * 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.performance.sampler;
    +
    +import com.google.common.base.Splitter;
    +import com.google.common.collect.Iterables;
    +
    +import java.io.BufferedReader;
    +import java.io.File;
    +import java.io.FileReader;
    +import java.io.IOException;
    +import java.util.AbstractMap;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Random;
    +import java.util.TreeMap;
    +
    +public class BiasedSampler implements Sampler {
    +  TreeMap<Double, Map.Entry<Integer, Integer>> discreteDistribution;
    +  public BiasedSampler(List<Map.Entry<Integer, Integer>>  discreteDistribution, int max) {
    +    this.discreteDistribution = createDistribution(discreteDistribution, max);
    +  }
    +
    +  public static List<Map.Entry<Integer, Integer>> readDistribution(File distrFile) throws IOException {
    +    List<Map.Entry<Integer, Integer>> ret = new ArrayList<>();
    +    System.out.println("Using biased sampler with the following biases:");
    +    try(BufferedReader br = new BufferedReader(new FileReader(distrFile))) {
    +      int sumLeft = 0;
    +      int sumRight = 0;
    +      for(String line = null;(line = br.readLine()) != null;) {
    +        if(line.startsWith("#")) {
    +          continue;
    +        }
    +        Iterable<String> it = Splitter.on(",").split(line.trim());
    +        int left = Integer.parseInt(Iterables.getFirst(it, null));
    --- End diff --
    
    done


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173930965
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/sampler/BiasedSampler.java ---
    @@ -0,0 +1,95 @@
    +/**
    + * 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.performance.sampler;
    +
    +import com.google.common.base.Splitter;
    +import com.google.common.collect.Iterables;
    +
    +import java.io.BufferedReader;
    +import java.io.File;
    +import java.io.FileReader;
    +import java.io.IOException;
    +import java.util.AbstractMap;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Random;
    +import java.util.TreeMap;
    +
    +public class BiasedSampler implements Sampler {
    +  TreeMap<Double, Map.Entry<Integer, Integer>> discreteDistribution;
    +  public BiasedSampler(List<Map.Entry<Integer, Integer>>  discreteDistribution, int max) {
    +    this.discreteDistribution = createDistribution(discreteDistribution, max);
    +  }
    +
    +  public static List<Map.Entry<Integer, Integer>> readDistribution(File distrFile) throws IOException {
    +    List<Map.Entry<Integer, Integer>> ret = new ArrayList<>();
    +    System.out.println("Using biased sampler with the following biases:");
    +    try(BufferedReader br = new BufferedReader(new FileReader(distrFile))) {
    +      int sumLeft = 0;
    +      int sumRight = 0;
    +      for(String line = null;(line = br.readLine()) != null;) {
    +        if(line.startsWith("#")) {
    +          continue;
    +        }
    +        Iterable<String> it = Splitter.on(",").split(line.trim());
    +        int left = Integer.parseInt(Iterables.getFirst(it, null));
    --- End diff --
    
    I wouldn't expect it to happen, but left/right will throw a NumberFormatException if the iterables list is empty. Do we need/want to be more robust about it?


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173928192
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/monitor/writers/ConsoleWriter.java ---
    @@ -0,0 +1,67 @@
    +/**
    + * 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.performance.load.monitor.writers;
    +
    +import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
    +import org.apache.metron.performance.load.monitor.Results;
    +
    +import java.text.DateFormat;
    +import java.text.SimpleDateFormat;
    +import java.util.ArrayList;
    +import java.util.Date;
    +import java.util.List;
    +import java.util.function.Consumer;
    +
    +public class ConsoleWriter implements Consumer<Writable> {
    +
    +  private String getSummary(DescriptiveStatistics stats) {
    +    return String.format("Mean: %d, Std Dev: %d", (int)stats.getMean(), (int)Math.sqrt(stats.getVariance()));
    +  }
    +
    +  @Override
    +  public void accept(Writable writable) {
    +    List<String> parts = new ArrayList<>();
    +    Date date = writable.getDate();
    +    for(Results r : writable.getResults()) {
    +      Long eps = r.getEps();
    +      if(eps != null) {
    +        String part = String.format(r.getFormat(), eps);
    +        if (r.getHistory().isPresent()) {
    +          part += " (" + getSummary(r.getHistory().get()) + ")";
    +        }
    +        parts.add(part);
    +      }
    +    }
    +    if(date != null) {
    +      DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    +      String header = dateFormat.format(date) + " - ";
    +      String emptyHeader = "";
    +      for (int i = 0; i < header.length(); ++i) {
    --- End diff --
    
    Could use `StringUtils.rightPad` to avoid the awkward append blanks loop.


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174787158
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/SendToKafka.java ---
    @@ -0,0 +1,107 @@
    +/**
    + * 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.performance.load;
    +
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.apache.kafka.clients.producer.ProducerRecord;
    +
    +import java.util.ArrayList;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.TimerTask;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Future;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Supplier;
    +
    +public class SendToKafka extends TimerTask {
    --- End diff --
    
    alright, done and done.


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173922548
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/MessageGenerator.java ---
    @@ -0,0 +1,48 @@
    +/**
    + * 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.performance.load;
    +
    +import org.apache.metron.performance.sampler.Sampler;
    +
    +import java.util.List;
    +import java.util.Random;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Supplier;
    +
    +public class MessageGenerator implements Supplier<String> {
    +  private static ThreadLocal<Random> rng = ThreadLocal.withInitial(() -> new Random());
    +  private static AtomicLong guidOffset = new AtomicLong(0);
    +  private static String guidPrefix = "6141faf6-a8ba-4044-ab80-";
    --- End diff --
    
    I assume this is being done to avoid the cost of creating an actual UUID?
    
    Why bother though? Why not just use the guidOffset directly? Is it to be at least somewhat close in terms of data size / format? In that case, why not just have the prefix be all zeroes or something easier to quickly read at a glance?


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174186316
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/LoadGenerator.java ---
    @@ -0,0 +1,165 @@
    +/**
    + * 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.performance.load;
    +
    +
    +import com.google.common.base.Joiner;
    +import org.apache.commons.cli.CommandLine;
    +import org.apache.commons.cli.PosixParser;
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.apache.metron.common.utils.KafkaUtils;
    +import org.apache.metron.performance.load.monitor.AbstractMonitor;
    +import org.apache.metron.performance.load.monitor.EPSGeneratedMonitor;
    +import org.apache.metron.performance.load.monitor.EPSThroughputWrittenMonitor;
    +import org.apache.metron.performance.load.monitor.MonitorTask;
    +import org.apache.metron.performance.load.monitor.writers.CSVWriter;
    +import org.apache.metron.performance.load.monitor.writers.ConsoleWriter;
    +import org.apache.metron.performance.load.monitor.writers.Writable;
    +import org.apache.metron.performance.load.monitor.writers.Writer;
    +import org.apache.metron.performance.sampler.BiasedSampler;
    +import org.apache.metron.performance.sampler.Sampler;
    +import org.apache.metron.performance.sampler.UnbiasedSampler;
    +
    +import java.io.File;
    +import java.util.ArrayList;
    +import java.util.EnumMap;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Optional;
    +import java.util.Timer;
    +import java.util.TimerTask;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Executors;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Consumer;
    +
    +public class LoadGenerator
    +{
    +  public static String CONSUMER_GROUP = "load.group";
    --- End diff --
    
    done


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174186458
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/LoadOptions.java ---
    @@ -0,0 +1,504 @@
    +/**
    + * 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.performance.load;
    +
    +import com.google.common.base.Joiner;
    +import org.apache.commons.cli.*;
    +import org.apache.metron.common.utils.JSONUtils;
    +import org.apache.metron.common.utils.cli.CLIOptions;
    +import org.apache.metron.performance.sampler.BiasedSampler;
    +import org.apache.metron.stellar.common.utils.ConversionUtils;
    +import org.apache.metron.common.utils.cli.OptionHandler;
    +
    +import javax.annotation.Nullable;
    +import java.io.BufferedReader;
    +import java.io.File;
    +import java.io.FileNotFoundException;
    +import java.io.FileReader;
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import java.util.EnumMap;
    +import java.util.List;
    +import java.util.Optional;
    +
    +public enum LoadOptions implements CLIOptions<LoadOptions> {
    +  HELP(new OptionHandler<LoadOptions>() {
    +
    +    @Override
    +    public String getShortCode() {
    +      return "h";
    +    }
    +
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      return new Option(s, "help", false, "Generate Help screen");
    +    }
    +  }),
    +  ZK(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "zk_quorum", true, "zookeeper quorum");
    +      o.setArgName("QUORUM");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(option.has(cli)) {
    +        return Optional.ofNullable(option.get(cli));
    +      }
    +      else {
    +        return Optional.empty();
    +      }
    +    }
    +
    +    @Override
    +    public String getShortCode() {
    +      return "z";
    +    }
    +  }),
    +  CONSUMER_GROUP(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "consumer_group", true, "Consumer Group.  The default is " + LoadGenerator.CONSUMER_GROUP);
    +      o.setArgName("GROUP_ID");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(option.has(cli)) {
    +        return Optional.ofNullable(option.get(cli));
    +      }
    +      else {
    +        return Optional.of(LoadGenerator.CONSUMER_GROUP);
    +      }
    +    }
    +
    +    @Override
    +    public String getShortCode() {
    +      return "cg";
    +    }
    +  }),
    +  BIASED_SAMPLE(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "sample_bias", true, "The discrete distribution to bias the sampling. " +
    +              "This is a CSV of 2 columns.  The first column is the % of the templates " +
    +              "and the 2nd column is the probability (0-100) that it's chosen.  For instance:\n" +
    +              "  20,80\n" +
    +              "  80,20\n" +
    +              "implies that 20% of the templates will comprise 80% of the output and the remaining 80% of the templates will comprise 20% of the output.");
    +      o.setArgName("BIAS_FILE");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(!option.has(cli)) {
    +        return Optional.empty();
    +      }
    +      File discreteDistributionFile  = new File(option.get(cli));
    +      if(discreteDistributionFile.exists()) {
    +        try {
    +
    +          return Optional.ofNullable(BiasedSampler.readDistribution(discreteDistributionFile));
    +        } catch (FileNotFoundException e) {
    +          throw new IllegalStateException("Unable to read distribution file: " + option.get(cli), e);
    +        } catch (IOException e) {
    +          throw new IllegalStateException("Unable to read distribution file: " + option.get(cli), e);
    +        }
    +      }
    +      else {
    +        throw new IllegalStateException("Unable to read distribution file: " + option.get(cli) + " file doesn't exist.");
    +      }
    +    }
    +
    +    @Override
    +    public String getShortCode() {
    +      return "bs";
    +    }
    +  })
    +  ,CSV(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "csv", true, "A CSV file to emit monitoring data to.  " +
    +              "The format is a CSV with the following schema: timestamp, (name, eps, historical_mean, historical_stddev)+");
    +      o.setArgName("CSV_FILE");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(!option.has(cli)) {
    +        return Optional.empty();
    +      }
    +      return Optional.of(new File(option.get(cli)));
    +    }
    +
    +    @Override
    +    public String getShortCode() {
    +      return "c";
    +    }
    +  })
    +  ,TEMPLATE(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "template", true, "The template file to use for generation.  This should be a file with a template per line with $METRON_TS and $METRON_GUID in the spots for timestamp and guid, if you so desire them.");
    +      o.setArgName("TEMPLATE_FILE");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(!option.has(cli)) {
    +        return Optional.empty();
    +      }
    +      File templateFile = new File(option.get(cli));
    +      if(templateFile.exists()) {
    +        List<String> templates = new ArrayList<>();
    +        try(BufferedReader br = new BufferedReader(new FileReader(templateFile))) {
    +          for(String line = null;(line = br.readLine()) != null;) {
    +            templates.add(line);
    +          }
    +          return Optional.of(templates);
    +        } catch (FileNotFoundException e) {
    --- End diff --
    
    done


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173917240
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/LoadGenerator.java ---
    @@ -0,0 +1,165 @@
    +/**
    + * 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.performance.load;
    +
    +
    +import com.google.common.base.Joiner;
    +import org.apache.commons.cli.CommandLine;
    +import org.apache.commons.cli.PosixParser;
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.apache.metron.common.utils.KafkaUtils;
    +import org.apache.metron.performance.load.monitor.AbstractMonitor;
    +import org.apache.metron.performance.load.monitor.EPSGeneratedMonitor;
    +import org.apache.metron.performance.load.monitor.EPSThroughputWrittenMonitor;
    +import org.apache.metron.performance.load.monitor.MonitorTask;
    +import org.apache.metron.performance.load.monitor.writers.CSVWriter;
    +import org.apache.metron.performance.load.monitor.writers.ConsoleWriter;
    +import org.apache.metron.performance.load.monitor.writers.Writable;
    +import org.apache.metron.performance.load.monitor.writers.Writer;
    +import org.apache.metron.performance.sampler.BiasedSampler;
    +import org.apache.metron.performance.sampler.Sampler;
    +import org.apache.metron.performance.sampler.UnbiasedSampler;
    +
    +import java.io.File;
    +import java.util.ArrayList;
    +import java.util.EnumMap;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Optional;
    +import java.util.Timer;
    +import java.util.TimerTask;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Executors;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Consumer;
    +
    +public class LoadGenerator
    +{
    +  public static String CONSUMER_GROUP = "load.group";
    +  public static long SEND_PERIOD_MS = 100;
    +  public static long MONITOR_PERIOD_MS = 1000*10;
    +  private static ExecutorService pool;
    +  private static ThreadLocal<KafkaProducer> kafkaProducer;
    +  public static AtomicLong numSent = new AtomicLong(0);
    +
    +  public static void main( String[] args ) throws Exception {
    +    CommandLine cli = LoadOptions.parse(new PosixParser(), args);
    +    EnumMap<LoadOptions, Optional<Object>> evaluatedArgs = LoadOptions.createConfig(cli);
    +    Map<String, Object> kafkaConfig = new HashMap<>();
    +    kafkaConfig.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    --- End diff --
    
    Kafka exposes these constants, rather than having to have them hardcoded.
    
    ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG
    ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG
    ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG
    ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173918861
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/LoadGenerator.java ---
    @@ -0,0 +1,165 @@
    +/**
    + * 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.performance.load;
    +
    +
    +import com.google.common.base.Joiner;
    +import org.apache.commons.cli.CommandLine;
    +import org.apache.commons.cli.PosixParser;
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.apache.metron.common.utils.KafkaUtils;
    +import org.apache.metron.performance.load.monitor.AbstractMonitor;
    +import org.apache.metron.performance.load.monitor.EPSGeneratedMonitor;
    +import org.apache.metron.performance.load.monitor.EPSThroughputWrittenMonitor;
    +import org.apache.metron.performance.load.monitor.MonitorTask;
    +import org.apache.metron.performance.load.monitor.writers.CSVWriter;
    +import org.apache.metron.performance.load.monitor.writers.ConsoleWriter;
    +import org.apache.metron.performance.load.monitor.writers.Writable;
    +import org.apache.metron.performance.load.monitor.writers.Writer;
    +import org.apache.metron.performance.sampler.BiasedSampler;
    +import org.apache.metron.performance.sampler.Sampler;
    +import org.apache.metron.performance.sampler.UnbiasedSampler;
    +
    +import java.io.File;
    +import java.util.ArrayList;
    +import java.util.EnumMap;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Optional;
    +import java.util.Timer;
    +import java.util.TimerTask;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Executors;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Consumer;
    +
    +public class LoadGenerator
    +{
    +  public static String CONSUMER_GROUP = "load.group";
    +  public static long SEND_PERIOD_MS = 100;
    +  public static long MONITOR_PERIOD_MS = 1000*10;
    +  private static ExecutorService pool;
    +  private static ThreadLocal<KafkaProducer> kafkaProducer;
    +  public static AtomicLong numSent = new AtomicLong(0);
    +
    +  public static void main( String[] args ) throws Exception {
    +    CommandLine cli = LoadOptions.parse(new PosixParser(), args);
    +    EnumMap<LoadOptions, Optional<Object>> evaluatedArgs = LoadOptions.createConfig(cli);
    +    Map<String, Object> kafkaConfig = new HashMap<>();
    +    kafkaConfig.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    +    kafkaConfig.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    +    kafkaConfig.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
    +    kafkaConfig.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
    +    if(LoadOptions.ZK.has(cli)) {
    +      String zkQuorum = (String) evaluatedArgs.get(LoadOptions.ZK).get();
    +      kafkaConfig.put("bootstrap.servers", Joiner.on(",").join(KafkaUtils.INSTANCE.getBrokersFromZookeeper(zkQuorum)));
    --- End diff --
    
    Same as before: ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG
    
    



---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173943133
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/monitor/AbstractMonitor.java ---
    @@ -0,0 +1,49 @@
    +/**
    + * 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.performance.load.monitor;
    +
    +import java.util.Optional;
    +import java.util.function.Supplier;
    +
    +public abstract class AbstractMonitor implements Supplier<Long>, MonitorNaming {
    +  private static final double EPSILON = 1e-6;
    +  protected Optional<?> kafkaTopic;
    +  protected long timestampPrevious = 0;
    +  public AbstractMonitor(Optional<?> kafkaTopic) {
    +    this.kafkaTopic = kafkaTopic;
    +  }
    +
    +  protected abstract Long monitor(double deltaTs);
    +
    +  @Override
    +  public Long get() {
    +    long timeStarted = System.currentTimeMillis();
    --- End diff --
    
    Nope, I'm missing my common sense is all.


---

[GitHub] metron issue #958: METRON-1483: Create a tool to monitor performance of the ...

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

    https://github.com/apache/metron/pull/958
  
    @justinleet thanks for the review.  I reacted to your comments either by fixing them or suggesting why I prefer what is there.  I will add a new set of tests in the next commit.


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174186403
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/LoadGenerator.java ---
    @@ -0,0 +1,165 @@
    +/**
    + * 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.performance.load;
    +
    +
    +import com.google.common.base.Joiner;
    +import org.apache.commons.cli.CommandLine;
    +import org.apache.commons.cli.PosixParser;
    +import org.apache.kafka.clients.producer.KafkaProducer;
    +import org.apache.metron.common.utils.KafkaUtils;
    +import org.apache.metron.performance.load.monitor.AbstractMonitor;
    +import org.apache.metron.performance.load.monitor.EPSGeneratedMonitor;
    +import org.apache.metron.performance.load.monitor.EPSThroughputWrittenMonitor;
    +import org.apache.metron.performance.load.monitor.MonitorTask;
    +import org.apache.metron.performance.load.monitor.writers.CSVWriter;
    +import org.apache.metron.performance.load.monitor.writers.ConsoleWriter;
    +import org.apache.metron.performance.load.monitor.writers.Writable;
    +import org.apache.metron.performance.load.monitor.writers.Writer;
    +import org.apache.metron.performance.sampler.BiasedSampler;
    +import org.apache.metron.performance.sampler.Sampler;
    +import org.apache.metron.performance.sampler.UnbiasedSampler;
    +
    +import java.io.File;
    +import java.util.ArrayList;
    +import java.util.EnumMap;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Optional;
    +import java.util.Timer;
    +import java.util.TimerTask;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Executors;
    +import java.util.concurrent.atomic.AtomicLong;
    +import java.util.function.Consumer;
    +
    +public class LoadGenerator
    +{
    +  public static String CONSUMER_GROUP = "load.group";
    +  public static long SEND_PERIOD_MS = 100;
    +  public static long MONITOR_PERIOD_MS = 1000*10;
    +  private static ExecutorService pool;
    +  private static ThreadLocal<KafkaProducer> kafkaProducer;
    +  public static AtomicLong numSent = new AtomicLong(0);
    +
    +  public static void main( String[] args ) throws Exception {
    +    CommandLine cli = LoadOptions.parse(new PosixParser(), args);
    +    EnumMap<LoadOptions, Optional<Object>> evaluatedArgs = LoadOptions.createConfig(cli);
    +    Map<String, Object> kafkaConfig = new HashMap<>();
    +    kafkaConfig.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    +    kafkaConfig.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    +    kafkaConfig.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
    +    kafkaConfig.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
    +    if(LoadOptions.ZK.has(cli)) {
    +      String zkQuorum = (String) evaluatedArgs.get(LoadOptions.ZK).get();
    +      kafkaConfig.put("bootstrap.servers", Joiner.on(",").join(KafkaUtils.INSTANCE.getBrokersFromZookeeper(zkQuorum)));
    +    }
    +    String groupId = evaluatedArgs.get(LoadOptions.CONSUMER_GROUP).get().toString();
    +    System.out.println("Consumer Group: " + groupId);
    +    kafkaConfig.put("group.id", groupId);
    --- End diff --
    
    done


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r174186800
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/sampler/UnbiasedSampler.java ---
    @@ -0,0 +1,28 @@
    +/**
    + * 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.performance.sampler;
    +
    +import java.util.Random;
    +
    +public class UnbiasedSampler implements Sampler {
    +
    +  @Override
    +  public int sample(Random rng, int limit) {
    +    return rng.nextInt(limit);
    --- End diff --
    
    done


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173920926
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/LoadOptions.java ---
    @@ -0,0 +1,504 @@
    +/**
    + * 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.performance.load;
    +
    +import com.google.common.base.Joiner;
    +import org.apache.commons.cli.*;
    +import org.apache.metron.common.utils.JSONUtils;
    +import org.apache.metron.common.utils.cli.CLIOptions;
    +import org.apache.metron.performance.sampler.BiasedSampler;
    +import org.apache.metron.stellar.common.utils.ConversionUtils;
    +import org.apache.metron.common.utils.cli.OptionHandler;
    +
    +import javax.annotation.Nullable;
    +import java.io.BufferedReader;
    +import java.io.File;
    +import java.io.FileNotFoundException;
    +import java.io.FileReader;
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import java.util.EnumMap;
    +import java.util.List;
    +import java.util.Optional;
    +
    +public enum LoadOptions implements CLIOptions<LoadOptions> {
    +  HELP(new OptionHandler<LoadOptions>() {
    +
    +    @Override
    +    public String getShortCode() {
    +      return "h";
    +    }
    +
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      return new Option(s, "help", false, "Generate Help screen");
    +    }
    +  }),
    +  ZK(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "zk_quorum", true, "zookeeper quorum");
    +      o.setArgName("QUORUM");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(option.has(cli)) {
    +        return Optional.ofNullable(option.get(cli));
    +      }
    +      else {
    +        return Optional.empty();
    +      }
    +    }
    +
    +    @Override
    +    public String getShortCode() {
    +      return "z";
    +    }
    +  }),
    +  CONSUMER_GROUP(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "consumer_group", true, "Consumer Group.  The default is " + LoadGenerator.CONSUMER_GROUP);
    +      o.setArgName("GROUP_ID");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(option.has(cli)) {
    +        return Optional.ofNullable(option.get(cli));
    +      }
    +      else {
    +        return Optional.of(LoadGenerator.CONSUMER_GROUP);
    +      }
    +    }
    +
    +    @Override
    +    public String getShortCode() {
    +      return "cg";
    +    }
    +  }),
    +  BIASED_SAMPLE(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "sample_bias", true, "The discrete distribution to bias the sampling. " +
    +              "This is a CSV of 2 columns.  The first column is the % of the templates " +
    +              "and the 2nd column is the probability (0-100) that it's chosen.  For instance:\n" +
    +              "  20,80\n" +
    +              "  80,20\n" +
    +              "implies that 20% of the templates will comprise 80% of the output and the remaining 80% of the templates will comprise 20% of the output.");
    +      o.setArgName("BIAS_FILE");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(!option.has(cli)) {
    +        return Optional.empty();
    +      }
    +      File discreteDistributionFile  = new File(option.get(cli));
    +      if(discreteDistributionFile.exists()) {
    +        try {
    +
    +          return Optional.ofNullable(BiasedSampler.readDistribution(discreteDistributionFile));
    +        } catch (FileNotFoundException e) {
    +          throw new IllegalStateException("Unable to read distribution file: " + option.get(cli), e);
    +        } catch (IOException e) {
    --- End diff --
    
    This is nitpicky, but the two catch branches are the same.  Is it worth either making them more unique or collapsing them?


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173926217
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/monitor/AbstractMonitor.java ---
    @@ -0,0 +1,49 @@
    +/**
    + * 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.performance.load.monitor;
    +
    +import java.util.Optional;
    +import java.util.function.Supplier;
    +
    +public abstract class AbstractMonitor implements Supplier<Long>, MonitorNaming {
    +  private static final double EPSILON = 1e-6;
    +  protected Optional<?> kafkaTopic;
    +  protected long timestampPrevious = 0;
    +  public AbstractMonitor(Optional<?> kafkaTopic) {
    +    this.kafkaTopic = kafkaTopic;
    +  }
    +
    +  protected abstract Long monitor(double deltaTs);
    +
    +  @Override
    +  public Long get() {
    +    long timeStarted = System.currentTimeMillis();
    --- End diff --
    
    I'd probably use `System.nanoTime` here (if it's not going to cause perf issues).  `System.currentTimeMillis` is, iirc, subject entirely to the system clock, which can be hit with daylight savings time and such.


---

[GitHub] metron pull request #958: METRON-1483: Create a tool to monitor performance ...

Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/metron/pull/958#discussion_r173921179
  
    --- Diff: metron-contrib/metron-performance/src/main/java/org/apache/metron/performance/load/LoadOptions.java ---
    @@ -0,0 +1,504 @@
    +/**
    + * 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.performance.load;
    +
    +import com.google.common.base.Joiner;
    +import org.apache.commons.cli.*;
    +import org.apache.metron.common.utils.JSONUtils;
    +import org.apache.metron.common.utils.cli.CLIOptions;
    +import org.apache.metron.performance.sampler.BiasedSampler;
    +import org.apache.metron.stellar.common.utils.ConversionUtils;
    +import org.apache.metron.common.utils.cli.OptionHandler;
    +
    +import javax.annotation.Nullable;
    +import java.io.BufferedReader;
    +import java.io.File;
    +import java.io.FileNotFoundException;
    +import java.io.FileReader;
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import java.util.EnumMap;
    +import java.util.List;
    +import java.util.Optional;
    +
    +public enum LoadOptions implements CLIOptions<LoadOptions> {
    +  HELP(new OptionHandler<LoadOptions>() {
    +
    +    @Override
    +    public String getShortCode() {
    +      return "h";
    +    }
    +
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      return new Option(s, "help", false, "Generate Help screen");
    +    }
    +  }),
    +  ZK(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "zk_quorum", true, "zookeeper quorum");
    +      o.setArgName("QUORUM");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(option.has(cli)) {
    +        return Optional.ofNullable(option.get(cli));
    +      }
    +      else {
    +        return Optional.empty();
    +      }
    +    }
    +
    +    @Override
    +    public String getShortCode() {
    +      return "z";
    +    }
    +  }),
    +  CONSUMER_GROUP(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "consumer_group", true, "Consumer Group.  The default is " + LoadGenerator.CONSUMER_GROUP);
    +      o.setArgName("GROUP_ID");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(option.has(cli)) {
    +        return Optional.ofNullable(option.get(cli));
    +      }
    +      else {
    +        return Optional.of(LoadGenerator.CONSUMER_GROUP);
    +      }
    +    }
    +
    +    @Override
    +    public String getShortCode() {
    +      return "cg";
    +    }
    +  }),
    +  BIASED_SAMPLE(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "sample_bias", true, "The discrete distribution to bias the sampling. " +
    +              "This is a CSV of 2 columns.  The first column is the % of the templates " +
    +              "and the 2nd column is the probability (0-100) that it's chosen.  For instance:\n" +
    +              "  20,80\n" +
    +              "  80,20\n" +
    +              "implies that 20% of the templates will comprise 80% of the output and the remaining 80% of the templates will comprise 20% of the output.");
    +      o.setArgName("BIAS_FILE");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(!option.has(cli)) {
    +        return Optional.empty();
    +      }
    +      File discreteDistributionFile  = new File(option.get(cli));
    +      if(discreteDistributionFile.exists()) {
    +        try {
    +
    +          return Optional.ofNullable(BiasedSampler.readDistribution(discreteDistributionFile));
    +        } catch (FileNotFoundException e) {
    +          throw new IllegalStateException("Unable to read distribution file: " + option.get(cli), e);
    +        } catch (IOException e) {
    +          throw new IllegalStateException("Unable to read distribution file: " + option.get(cli), e);
    +        }
    +      }
    +      else {
    +        throw new IllegalStateException("Unable to read distribution file: " + option.get(cli) + " file doesn't exist.");
    +      }
    +    }
    +
    +    @Override
    +    public String getShortCode() {
    +      return "bs";
    +    }
    +  })
    +  ,CSV(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "csv", true, "A CSV file to emit monitoring data to.  " +
    +              "The format is a CSV with the following schema: timestamp, (name, eps, historical_mean, historical_stddev)+");
    +      o.setArgName("CSV_FILE");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(!option.has(cli)) {
    +        return Optional.empty();
    +      }
    +      return Optional.of(new File(option.get(cli)));
    +    }
    +
    +    @Override
    +    public String getShortCode() {
    +      return "c";
    +    }
    +  })
    +  ,TEMPLATE(new OptionHandler<LoadOptions>() {
    +    @Nullable
    +    @Override
    +    public Option apply(@Nullable String s) {
    +      Option o = new Option(s, "template", true, "The template file to use for generation.  This should be a file with a template per line with $METRON_TS and $METRON_GUID in the spots for timestamp and guid, if you so desire them.");
    +      o.setArgName("TEMPLATE_FILE");
    +      o.setRequired(false);
    +      return o;
    +    }
    +
    +    @Override
    +    public Optional<Object> getValue(LoadOptions option, CommandLine cli) {
    +      if(!option.has(cli)) {
    +        return Optional.empty();
    +      }
    +      File templateFile = new File(option.get(cli));
    +      if(templateFile.exists()) {
    +        List<String> templates = new ArrayList<>();
    +        try(BufferedReader br = new BufferedReader(new FileReader(templateFile))) {
    +          for(String line = null;(line = br.readLine()) != null;) {
    +            templates.add(line);
    +          }
    +          return Optional.of(templates);
    +        } catch (FileNotFoundException e) {
    --- End diff --
    
    Same deal on the identical catches.


---