Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.zegelin.cassandra.exporter;

import com.zegelin.cassandra.exporter.MBeanGroupMetricFamilyCollector.Factory;
import com.zegelin.cassandra.exporter.cli.HarvesterOptions;

import java.util.List;
import java.util.ServiceLoader;

/**
* Service Provider interface whose implementations will be loaded via {@link ServiceLoader}.
*
* <p> Allows runtime modules to provide pluggable metrics via classpath registration.
*
*/
public interface FactoriesProvider
{
/**
* Provides a list of {@link Factory} to be registered on the exporter.
*
* @param metadataFactory
* @param options
* @return factories
*/
List<Factory> getFactories(final MetadataFactory metadataFactory, final HarvesterOptions options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ public boolean equals(final Object o) {

protected Harvester(final MetadataFactory metadataFactory, final HarvesterOptions options) {
this.collectorFactories = new ArrayList<>(new FactoriesSupplier(metadataFactory, options).get());

ServiceLoader<FactoriesProvider> providers = ServiceLoader.load(FactoriesProvider.class);
providers.forEach(p -> collectorFactories.addAll(p.getFactories(metadataFactory, options)));

this.metadataFactory = metadataFactory;
this.exclusions = options.exclusions;
this.enabledGlobalLabels = options.globalLabels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public MBeanGroupMetricFamilyCollector removeMBean(final ObjectName mBeanName) {
public abstract Stream<MetricFamily> collect();


protected interface Factory {
public interface Factory
{
/**
* Create a {@link MBeanGroupMetricFamilyCollector} for the given MBean, or null if this collector
* doesn't support the given MBean.
Expand Down