EdColeman commented on a change in pull request #1381: Update gc metrics reporting to use hadoop metrics2 URL: https://github.com/apache/accumulo/pull/1381#discussion_r332140111 ########## File path: test/src/main/java/org/apache/accumulo/test/metrics/MetricsFileTailer.java ########## @@ -0,0 +1,255 @@ +/* + * 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.configuration2.Configuration; +import org.apache.commons.configuration2.FileBasedConfiguration; +import org.apache.commons.configuration2.PropertiesConfiguration; +import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; +import org.apache.commons.configuration2.builder.fluent.Parameters; +import org.apache.commons.configuration2.ex.ConfigurationException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class allows testing of the publishing to the hadoop metrics2 system by processing a file + * for metric records (written as a line.) The file should be configured using the hadoop metrics2 + * 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 vaule 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 Lock lock = new ReentrantLock(); + private AtomicBoolean running = new AtomicBoolean(Boolean.TRUE); + + private AtomicLong lastUpdate = new AtomicLong(0); + private long startTime = System.nanoTime(); + + private int lineCounter = 0; + private String[] lineBuffer = new String[BUFFER_SIZE]; + + private final String metricsFilename; + + /** + * Create an instance that will tail a metrics2 file. The filename / path is determined by the + * hadoop-metrics2-accumulo.properties sink configuration for the metrics prefix that is provided. + * + * @param metricsPrefix + * the prefix in the metrics2 configuration. + */ + public MetricsFileTailer(final String metricsPrefix) { Review comment: The first attempt did have a custom sink that used http / REST, but in minimizing adding external dependencies, it made porting from 1.9 to 2.x more difficult. There were also conflicts with hadoop metrics2 and the hadoop shaded jars that I did not resolve. The approach may still be valid and will be revisited going forward, but the file sync does provide some basic functionality that was useful to testing during development. ---------------------------------------------------------------- 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