You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2020/02/04 14:41:27 UTC

[GitHub] [accumulo] milleruntime commented on a change in pull request #1406: Backport gc metrics to 1.9.x to use hadoop metrics2.

milleruntime commented on a change in pull request #1406: Backport gc metrics to 1.9.x to use hadoop metrics2.
URL: https://github.com/apache/accumulo/pull/1406#discussion_r374698582
 
 

 ##########
 File path: test/src/main/java/org/apache/accumulo/test/metrics/MetricsFileTailer.java
 ##########
 @@ -0,0 +1,261 @@
+/*
+ * 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.accumulo.test.metrics;
+
+import java.io.File;
+import java.io.RandomAccessFile;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class allows testing of the publishing to the hadoop metrics system by processing a file for
+ * metric records (written as a line.) The file should be configured using the hadoop metrics
+ * properties as a file based sink with the prefix that is provided on instantiation of the
+ * instance.
+ *
+ * This class will simulate tail-ing a file and is intended to be run in a separate thread. When the
+ * underlying file has data written, the value returned by getLastUpdate will change, and the last
+ * line can be retrieved with getLast().
+ */
+public class MetricsFileTailer implements Runnable, AutoCloseable {
+
+  private static final Logger log = LoggerFactory.getLogger(MetricsFileTailer.class);
+
+  private static final int BUFFER_SIZE = 4;
+
+  private final String metricsPrefix;
+
+  private final Lock lock = new ReentrantLock();
+  private final AtomicBoolean running = new AtomicBoolean(Boolean.TRUE);
+
+  private final AtomicLong lastUpdate = new AtomicLong(0);
+  private final long startTime = System.nanoTime();
+
+  private int lineCounter = 0;
+  private final String[] lineBuffer = new String[BUFFER_SIZE];
+
+  private final String metricsFilename;
+
+  /**
+   * Create an instance that will tail a metrics file. The filename / path is determined by the
+   * hadoop-metrics-accumulo.properties sink configuration for the metrics prefix that is provided.
+   *
+   * @param metricsPrefix
+   *          the prefix in the metrics configuration.
+   */
+  public MetricsFileTailer(final String metricsPrefix) {
+
+    this.metricsPrefix = metricsPrefix;
+
+    Configuration sub = loadMetricsConfig();
+
+    // dump received configuration keys received.
+    if (log.isTraceEnabled()) {
+      // required for commons configuration - version 1.6
+      @SuppressWarnings("unchecked")
+      Iterator<String> keys = sub.getKeys();
+      while (keys.hasNext()) {
+        log.trace("configuration key:{}", keys.next());
+      }
+    }
+
+    if (sub.containsKey("filename")) {
+      metricsFilename = sub.getString("filename");
+    } else {
+      metricsFilename = "";
+    }
+
+  }
+
+  /**
+   * Create an instance by specifying a file directly instead of using the metrics configuration -
+   * mainly for testing.
+   *
+   * @param metricsPrefix
+   *          generally can be ignored.
+   * @param filename
+   *          the path / file to be monitored.
+   */
+  MetricsFileTailer(final String metricsPrefix, final String filename) {
+    this.metricsPrefix = metricsPrefix;
+    metricsFilename = filename;
+  }
+
+  /**
+   * Look for the accumulo metrics configuration file on the classpath and return the subset for the
+   * http sink.
+   *
+   * @return a configuration with http sink properties.
+   */
+  private Configuration loadMetricsConfig() {
+    try {
+
+      final URL propUrl =
+          getClass().getClassLoader().getResource(MetricsTestSinkProperties.METRICS_PROP_FILENAME);
+
+      if (propUrl == null) {
+        throw new IllegalStateException(
+            "Could not find " + MetricsTestSinkProperties.METRICS_PROP_FILENAME + " on classpath");
+      }
+
+      String filename = propUrl.getFile();
+
+      // Read data from this file
+      // File propertiesFile = new File(filename);
+
+      // ConfigurationFactory factory = new ConfigurationFactory(filename);
+      Configuration config = new PropertiesConfiguration(filename);
+
+      // Configurations configs = new Configurations();
+      //
+      // Configuration config = configs.properties(new File("config.properties"));
+      // FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
+      // new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
+      // .configure(params.fileBased().setFile(propertiesFile));
+      //
+      // Configuration config = builder.getConfiguration();
 
 Review comment:
   Should drop this commented out code.  Can be done in a separate commit.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services