io.streamnative.pulsar.handlers.kop.stats.StatsLogger Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pulsar-protocol-handler-kafka Show documentation
Show all versions of pulsar-protocol-handler-kafka Show documentation
Kafka on Pulsar implemented using Pulsar Protocol Handler
/**
* Licensed 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 io.streamnative.pulsar.handlers.kop.stats;
import org.apache.bookkeeper.stats.Counter;
import org.apache.bookkeeper.stats.Gauge;
import org.apache.bookkeeper.stats.OpStatsLogger;
/**
* A simple interface that exposes just 2 useful methods. One to get the logger for an Op stat
* and another to get the logger for a simple stat
*/
public interface StatsLogger {
/**
* @param name
* Stats Name
* @return Get the logger for an OpStat described by the name.
*/
OpStatsLogger getOpStatsLogger(String name);
/**
* @param name
* Stats Name
* @return Get the logger for a simple stat described by the name
*/
Counter getCounter(String name);
/**
* Register given gauge as name name.
*
* @param name
* gauge name
* @param gauge
* gauge function
*/
void registerGauge(String name, Gauge gauge);
/**
* Unregister given gauge from name name.
*
* @param name
* name of the gauge
* @param gauge
* gauge function
*/
void unregisterGauge(String name, Gauge gauge);
/**
* Provide the stats logger under scope name.
*
* @param name
* scope name.
* @return stats logger under scope name.
*/
StatsLogger scope(String name);
/**
* Provide the stats logger with an attached label.
*
* @param labelName
* the name of the label.
* @param labelValue
* the value of the label.
*
* @return stats logger under scope name.
*/
default StatsLogger scopeLabel(String labelName, String labelValue) {
// Provide default implementation for backward compatibility
return scope(new StringBuilder()
.append(labelName)
.append('_')
.append(labelValue.replace('.', '_')
.replace('-', '_')
.replace(':', '_'))
.toString());
}
/**
* Remove the given statsLogger for scope name.
* It can be no-op if the underlying stats provider doesn't have the ability to remove scope.
*
* @param name name of the scope
* @param statsLogger the stats logger of this scope.
*/
void removeScope(String name, StatsLogger statsLogger);
}