diff --git a/server/src/main/java/io/druid/server/emitter/EmitterModule.java b/server/src/main/java/io/druid/server/emitter/EmitterModule.java index 9969fef66b2..a0e08225ee1 100644 --- a/server/src/main/java/io/druid/server/emitter/EmitterModule.java +++ b/server/src/main/java/io/druid/server/emitter/EmitterModule.java @@ -31,6 +31,7 @@ import com.google.inject.Module; import com.google.inject.Provider; import com.google.inject.Provides; import com.google.inject.TypeLiteral; +import com.google.inject.multibindings.MapBinder; import com.google.inject.name.Named; import com.google.inject.name.Names; import com.metamx.emitter.EmittingLogger; @@ -45,6 +46,7 @@ import io.druid.server.DruidNode; import java.lang.annotation.Annotation; import java.util.List; +import java.util.Map; import java.util.Properties; /** @@ -76,24 +78,35 @@ public class EmitterModule implements Module binder.install(new ComposingEmitterModule()); binder.bind(Emitter.class).toProvider(new EmitterProvider(emitterType)).in(LazySingleton.class); + + MapBinder extraServiceDimensions = MapBinder.newMapBinder( + binder, + String.class, + String.class, + ExtraServiceDimensions.class + ); + String version = getClass().getPackage().getImplementationVersion(); + extraServiceDimensions + .addBinding("version") + .toInstance(Strings.nullToEmpty(version)); // Version is null during `mvn test`. } @Provides @ManageLifecycle - public ServiceEmitter getServiceEmitter(@Self Supplier configSupplier, Emitter emitter) + public ServiceEmitter getServiceEmitter( + @Self Supplier configSupplier, + Emitter emitter, + @ExtraServiceDimensions Map extraServiceDimensions + ) { final DruidNode config = configSupplier.get(); - String version = getClass().getPackage().getImplementationVersion(); - final ImmutableMap otherServiceDimensions = ImmutableMap.of( - "version", - Strings.nullToEmpty(version) // Version is null during `mvn test`. - ); log.info("Underlying emitter for ServiceEmitter: %s", emitter); + log.info("Extra service dimensions: %s", extraServiceDimensions); final ServiceEmitter retVal = new ServiceEmitter( config.getServiceName(), config.getHostAndPortToUse(), emitter, - otherServiceDimensions + ImmutableMap.copyOf(extraServiceDimensions) ); EmittingLogger.registerEmitter(retVal); return retVal; diff --git a/server/src/main/java/io/druid/server/emitter/ExtraServiceDimensions.java b/server/src/main/java/io/druid/server/emitter/ExtraServiceDimensions.java new file mode 100644 index 00000000000..09d3627c062 --- /dev/null +++ b/server/src/main/java/io/druid/server/emitter/ExtraServiceDimensions.java @@ -0,0 +1,45 @@ +/* + * Licensed to Metamarkets Group Inc. (Metamarkets) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Metamarkets 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 io.druid.server.emitter; + +import com.google.inject.BindingAnnotation; +import io.druid.guice.annotations.PublicApi; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation to inject extra dimensions, added to all events, emitted via {@link EmitterModule#getServiceEmitter}. + * + * For example, write this in a body of {@link com.google.inject.Module#configure} of your extension module): + * + * MapBinder extraDims = + * MapBinder.newMapBinder(binder, String.class, String.class, ExtraServiceDimensions.class); + * extraDims.addBinding("foo").toInstance("bar"); + */ +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@BindingAnnotation +@PublicApi +public @interface ExtraServiceDimensions +{ +}