You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "gianm (via GitHub)" <gi...@apache.org> on 2023/05/03 04:21:32 UTC

[GitHub] [druid] gianm commented on a diff in pull request #14200: Ability to optionally bind extra service dimensions to ServiceEvents

gianm commented on code in PR #14200:
URL: https://github.com/apache/druid/pull/14200#discussion_r1183225680


##########
server/src/main/java/org/apache/druid/server/emitter/ExtraServiceDimensions.java:
##########
@@ -29,12 +29,25 @@
 
 /**
  * Annotation to inject extra dimensions, added to all events, emitted via {@link EmitterModule#getServiceEmitter}.
- *
+ * <p/>
  * For example, write this in a body of {@link com.google.inject.Module#configure} of your extension module):
- *
+ * <p/>
  * MapBinder<String, String> extraDims =
  *     MapBinder.newMapBinder(binder, String.class, String.class, ExtraServiceDimensions.class);
  * extraDims.addBinding("foo").toInstance("bar");
+ * <p/>
+ * If a module wishes to optionally bind service dimensions they may do so by using the binding to
+ * Map<String, Optional<String>. The key is only added to the service dimensions that are emitted if the Optional is
+ * present.
+ * <p/>
+ * MapBinder<String, Optional<String>> extraDims =
+ *     MapBinder.newMapBinder(
+ *        binder,
+ *        new TypeLiteral<String>() {},
+ *        new TypeLiteral<Optional<String>>() {},
+ *        ExtraServiceDimensions.class
+ * );
+ * extraDims.addBinding("foo").toInstance(Optional.fromNullable(bar));

Review Comment:
   What's the advantage of doing this, vs. keeping `String` -> `String` and having modules avoid calling `addBinding` if `bar` is null?



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org