Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatible dropwizard metrics #9416

Merged
merged 14 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions pinot-plugins/pinot-metrics/pinot-compound-metrics/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>pinot-metrics</artifactId>
<groupId>org.apache.pinot</groupId>
<version>1.3.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>pinot-compound-metrics</artifactId>
<name>Pinot Compound Metrics</name>
<url>https://pinot.apache.org/</url>
<properties>
<pinot.root>${basedir}/../../..</pinot.root>
<phase.prop>package</phase.prop>
</properties>

<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.apache.pinot</groupId>
<artifactId>pinot-spi</artifactId>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service-annotations</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* 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.pinot.plugin.metrics.compound;

import com.google.common.base.Preconditions;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.pinot.spi.metrics.PinotMetric;


public abstract class AbstractCompoundPinotMetric<M extends PinotMetric> implements PinotMetric {
protected final List<M> _metrics;

public AbstractCompoundPinotMetric(List<M> metrics) {
Preconditions.checkArgument(!metrics.isEmpty(), "At least one meter is needed");
_metrics = metrics;
}

@Override
public Object getMetric() {
return _metrics.stream().map(PinotMetric::getMetric).collect(Collectors.toList());
}

protected M getSomeMeter() {
return _metrics.get(0);
}

public M getMeter(int index) {
return _metrics.get(index);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* 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.pinot.plugin.metrics.compound;

import java.util.List;
import org.apache.pinot.spi.metrics.PinotCounter;


public class CompoundPinotCounter extends AbstractCompoundPinotMetric<PinotCounter> implements PinotCounter {
public CompoundPinotCounter(List<PinotCounter> metrics) {
super(metrics);
}

@Override
public Object getCounter() {
return getSomeMeter().getCounter();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* 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.pinot.plugin.metrics.compound;

import java.util.List;
import java.util.function.Supplier;
import org.apache.pinot.spi.metrics.PinotGauge;


public class CompoundPinotGauge<T> extends AbstractCompoundPinotMetric<PinotGauge<T>> implements PinotGauge<T> {
public CompoundPinotGauge(List<PinotGauge<T>> meters) {
super(meters);
}

@Override
public Object getGauge() {
return getSomeMeter().getGauge();
}

@Override
public T value() {
return getSomeMeter().value();
}

@Override
public void setValue(T value) {
_metrics.forEach(m -> m.setValue(value));
}

@Override
public void setValueSupplier(Supplier<T> valueSupplier) {
_metrics.forEach(m -> m.setValueSupplier(valueSupplier));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* 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.pinot.plugin.metrics.compound;

import java.util.List;
import org.apache.pinot.spi.metrics.PinotHistogram;


public class CompoundPinotHistogram extends AbstractCompoundPinotMetric<PinotHistogram> implements PinotHistogram {
public CompoundPinotHistogram(List<PinotHistogram> metrics) {
super(metrics);
}

@Override
public Object getHistogram() {
return getMetric();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* 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.pinot.plugin.metrics.compound;

import java.util.List;
import org.apache.pinot.spi.metrics.PinotJmxReporter;


public class CompoundPinotJmxReporter implements PinotJmxReporter {
private final List<PinotJmxReporter> _reporters;

public CompoundPinotJmxReporter(List<PinotJmxReporter> reporters) {
_reporters = reporters;
}

@Override
public void start() {
for (PinotJmxReporter reporter : _reporters) {
reporter.start();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* 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.pinot.plugin.metrics.compound;

import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.pinot.spi.metrics.PinotMeter;


public class CompoundPinotMeter extends AbstractCompoundPinotMetric<PinotMeter> implements PinotMeter {
public CompoundPinotMeter(List<PinotMeter> meters) {
super(meters);
}

@Override
public void mark() {
for (PinotMeter meter : _metrics) {
meter.mark();
}
}

@Override
public void mark(long unitCount) {
for (PinotMeter meter : _metrics) {
meter.mark(unitCount);
}
}

@Override
public long count() {
return getSomeMeter().count();
}

@Override
public Object getMetered() {
return getSomeMeter().getMetered();
}

@Override
public TimeUnit rateUnit() {
return getSomeMeter().rateUnit();
}

@Override
public String eventType() {
return getSomeMeter().eventType();
}

@Override
public double fifteenMinuteRate() {
return getSomeMeter().fifteenMinuteRate();
}

@Override
public double fiveMinuteRate() {
return getSomeMeter().fiveMinuteRate();
}

@Override
public double meanRate() {
return getSomeMeter().meanRate();
}

@Override
public double oneMinuteRate() {
return getSomeMeter().oneMinuteRate();
}
}
Loading
Loading