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


##########
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:
   Looks like its possible to inject the node roles into the module class. 
meaning we dont need the optional
   
   
   ```java
    private Set<NodeRole> nodeRoles;
   
     @Inject
     public void setNodeRoles(@Self Set<NodeRole> nodeRoles)
     {
       this.nodeRoles = nodeRoles;
     }
   
     @Override
     public void configure(Binder binder)
     {
       MapBinder<String, String> extraDims = MapBinder.newMapBinder(
           binder,
           String.class,
           String.class,
           ExtraServiceDimensions.class
       );
   
       // add information related to tasks for peons
       if (nodeRoles.contains(NodeRole.PEON)) {
         extraDims.addBinding("foo").toProvider(new Provider<String>()
         {
           @Inject
           private Injector injector;
   
   
           @Override
           public String get()
           {
             return injector.getInstance(Task.class).getId();
           }
         });
   }
   ```
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to