ctubbsii 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_r331298587
########## 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: I wonder if it would be easier if we wrote our own metrics sink to use for testing, rather than use the FileSink with something like this. Could be something for future. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
