-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add dataSource and taskId dimensions to GroupByStatsMonitor for peons #18709
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
Changes from all commits
72ed511
be53bda
d788744
e9d29bd
32b6da6
1f5492a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,11 @@ | |
| import org.apache.druid.server.coordination.BroadcastDatasourceLoadingSpec; | ||
| import org.apache.druid.server.lookup.cache.LookupLoadingSpec; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * This holder is only applicable to {@code CliPeon} servers. | ||
| */ | ||
| public class DataSourceTaskIdHolder | ||
| { | ||
| public static final String DATA_SOURCE_BINDING = "druidDataSource"; | ||
|
|
@@ -34,6 +39,7 @@ public class DataSourceTaskIdHolder | |
| @Named(DATA_SOURCE_BINDING) | ||
| @Inject(optional = true) | ||
| String dataSource = null; | ||
|
|
||
| @Named(TASK_ID_BINDING) | ||
| @Inject(optional = true) | ||
| String taskId = null; | ||
|
|
@@ -46,11 +52,19 @@ public class DataSourceTaskIdHolder | |
| @Inject(optional = true) | ||
| BroadcastDatasourceLoadingSpec broadcastDatasourceLoadingSpec = BroadcastDatasourceLoadingSpec.ALL; | ||
|
|
||
| /** | ||
| * @return the taskId for CliPeon servers; {@code null} for all other servers. | ||
| */ | ||
| @Nullable | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When can this be null?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For peons, the For all other servers, this would be null as these fields are initialized to null:: @Named(DATA_SOURCE_BINDING)
@Inject(optional = true)
String dataSource = null;
@Named(TASK_ID_BINDING)
@Inject(optional = true)
String taskId = null;
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a short javadoc on these getters mentioning that these are non-null only for CliPeon servers. In a follow up PR, we should also fix up the way that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added javadoc!
Yeah, there's some commentary on why it's setup the way it is. I think we'll need to revisit this Guice bindings for this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, given that we have embedded tests now, it should be easy to fix as we can iterate much faster. |
||
| public String getDataSource() | ||
| { | ||
| return dataSource; | ||
| } | ||
|
|
||
| /** | ||
| * @return the dataSource for CliPeon servers; {@code null} for all other servers. | ||
| */ | ||
| @Nullable | ||
| public String getTaskId() | ||
| { | ||
| return taskId; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,9 +27,11 @@ | |
| import org.apache.druid.java.util.emitter.service.ServiceEmitter; | ||
| import org.apache.druid.java.util.emitter.service.ServiceMetricEvent; | ||
| import org.apache.druid.java.util.metrics.AbstractMonitor; | ||
| import org.apache.druid.java.util.metrics.MonitorUtils; | ||
| import org.apache.druid.query.groupby.GroupByStatsProvider; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.Map; | ||
|
|
||
| @LoadScope(roles = { | ||
| NodeRole.BROKER_JSON_NAME, | ||
|
|
@@ -41,21 +43,28 @@ public class GroupByStatsMonitor extends AbstractMonitor | |
| { | ||
| private final GroupByStatsProvider groupByStatsProvider; | ||
| private final BlockingPool<ByteBuffer> mergeBufferPool; | ||
| private final Map<String, String[]> dimensions; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe rename to In fact, I wonder if it wouldn't be cleaner to just bind the datasource and taskID as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can rename, but I left this field as
This is a good idea! I will try to take a stab at it separately and put up a PR as it affects all monitors - we'll need to rework the Guice bindings and likely need to reconcile how the extra service dimensions will be bound to monitors in a backwards-compatible manner too (
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I see, thanks for the clarification. |
||
|
|
||
| @Inject | ||
| public GroupByStatsMonitor( | ||
| GroupByStatsProvider groupByStatsProvider, | ||
| @Merging BlockingPool<ByteBuffer> mergeBufferPool | ||
| @Merging BlockingPool<ByteBuffer> mergeBufferPool, | ||
| DataSourceTaskIdHolder dataSourceTaskIdHolder | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please pass a dimensions map here instead of this holder since the holder class has meaning only for peons.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this monitor is injected, I don’t think it can accept a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we can leave that for now. When we fix up the binding of |
||
| ) | ||
| { | ||
| this.groupByStatsProvider = groupByStatsProvider; | ||
| this.mergeBufferPool = mergeBufferPool; | ||
| this.dimensions = MonitorsConfig.mapOfDatasourceAndTaskID( | ||
| dataSourceTaskIdHolder.getDataSource(), | ||
| dataSourceTaskIdHolder.getTaskId() | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean doMonitor(ServiceEmitter emitter) | ||
| { | ||
| final ServiceMetricEvent.Builder builder = new ServiceMetricEvent.Builder(); | ||
| MonitorUtils.addDimensionsToBuilder(builder, dimensions); | ||
|
|
||
| emitter.emit(builder.setMetric("mergeBuffer/pendingRequests", mergeBufferPool.getPendingRequests())); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| import org.apache.druid.java.util.metrics.Monitor; | ||
| import org.apache.druid.query.DruidMetrics; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import javax.validation.constraints.NotNull; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
|
|
@@ -79,13 +80,23 @@ public String toString() | |
| '}'; | ||
| } | ||
|
|
||
| public static Map<String, String[]> mapOfDatasourceAndTaskID(final String datasource, final String taskId) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of adding a new method, let's do the following instead:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done.
It looks like the docs for the six monitors that use this method don’t specify their dimensions clearly. I’ve added a general info note under the Real-time metrics seciton. Please let me know if I missed anything. |
||
| /** | ||
| * @return a map of {@code datasource} and {@code taskId} dimensions if provided; otherwise, returns an empty map. | ||
| * When {@code taskId} is provided, both {@link DruidMetrics#ID} and {@link DruidMetrics#TASK_ID} dimensions are added | ||
| * to the map for backward compatibility. {@link DruidMetrics#ID} is deprecated because it's ambiguous and will be | ||
| * removed in a future release. | ||
| */ | ||
| public static Map<String, String[]> mapOfDatasourceAndTaskID( | ||
| @Nullable final String datasource, | ||
| @Nullable final String taskId | ||
| ) | ||
| { | ||
| final ImmutableMap.Builder<String, String[]> builder = ImmutableMap.builder(); | ||
| if (datasource != null) { | ||
| builder.put(DruidMetrics.DATASOURCE, new String[]{datasource}); | ||
| } | ||
| if (taskId != null) { | ||
| builder.put(DruidMetrics.TASK_ID, new String[]{taskId}); | ||
| builder.put(DruidMetrics.ID, new String[]{taskId}); | ||
| } | ||
| return builder.build(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.