Skip to content

Add stats to KillUnusedSegments coordinator duty - #14782

Merged
zachjsh merged 11 commits into
apache:masterfrom
zachjsh:auto-kill-stats
Aug 10, 2023
Merged

zachjsh merged 11 commits into
apache:masterfrom
zachjsh:auto-kill-stats

Conversation

@zachjsh

@zachjsh zachjsh commented Aug 8, 2023 •

Copy link
Copy Markdown
Contributor

Description

Added the following metrics, which are calculated from the KillUnusedSegments coordinatorDuty

"killTask/availableSlot/count": calculates the number remaining task slots available for auto kill
"killTask/maxSlot/count": calculates the maximum number of tasks available for auto kill
"killTask/task/count": calculates the number of tasks submitted by auto kill.

Release note

NEW: metrics added for auto kill

"killTask/availableSlot/count": calculates the number remaining task slots available for auto kill
"killTask/maxSlot/count": calculates the maximum number of tasks available for auto kill
"killTask/task/count": calculates the number of tasks submitted by auto kill.

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

@jasonk000 jasonk000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good


private static final Logger LOG = new Logger(CompactSegments.class);

private static final Predicate<TaskStatusPlus> TASK_PREDICATE =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name this COMPACTION_TASK_PREDICATE, or IS_COMPACTION_TASK?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

// the tasks of the unknown taskType as the killTask. This is because it's important to not run
// killTasks more than the configured limit at any time which might impact to the ingestion
// performance.
if (status.getType() == null || (taskPredicate.apply(status))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I observe something unclear in the null check here:

  • First, we assume status is non-null because we deref status
  • The, we call predicate; predicate first checks if status is null (when it can never be because of deref/NPE)
  • Then we do comparison.

I think it would be good idea to clarify in Javadoc (and code) either one or the other situation

  • Predicate<TaskStatusPlus> predicate "must be able to accept null", OR, predicate "will never be called with null".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, added here

{
public static final String KILL_TASK_TYPE = "kill";
public static final String TASK_ID_PREFIX = "coordinator-issued";
public static final Predicate<TaskStatusPlus> TASK_PREDICATE =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar here, I think we should give the name a more clear name, IS_KILL_TASK?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we choose to have a more specific name, I think it should say IS_AUTO_KILL_TASK instead of IS_KILL_TASK as the predicate excludes manual kill tasks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

final long currentTimeMillis = System.currentTimeMillis();
if (CollectionUtils.isNullOrEmpty(dataSourcesToKill)) {
log.debug("No eligible datasource to kill unused segments.");
} else if (lastKillTime + period > currentTimeMillis) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this check be pulled out earlier in the function; ie: we can avoid calculation altogether if the kill time was too recent. Not sure if I missed something.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

availableKillTaskSlots < dataSourcesToKill.size()
? StringUtils.format(
" Datasources skipped: %s",
ImmutableList.copyOf(dataSourcesToKill).subList(submittedTasks, dataSourcesToKill.size())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw, I think this might need to be wrapped in an log.isDebug(), since the string format will likely be executed even if debug is not enabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@jasonk000 jasonk000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swapping to request changes based on prior comments

@suneet-s suneet-s left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes for

  • Remove the use of the constant TaskStats.EMPTY across coordinator runs
  • Please add these new metrics to the metrics.md file, perhaps next to the compactTask/* metrics as these are related

{
public static final String KILL_TASK_TYPE = "kill";
public static final String TASK_ID_PREFIX = "coordinator-issued";
public static final Predicate<TaskStatusPlus> TASK_PREDICATE =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we choose to have a more specific name, I think it should say IS_AUTO_KILL_TASK instead of IS_KILL_TASK as the predicate excludes manual kill tasks

Comment thread server/src/main/java/org/apache/druid/server/coordinator/stats/Stats.java Outdated
Comment thread server/src/main/java/org/apache/druid/server/coordinator/stats/Stats.java Outdated
zachjsh and others added 3 commits August 10, 2023 00:17
Co-authored-by: Suneet Saldanha <suneet@apache.org>
…CoordinatorDutyUtils.java

Co-authored-by: Suneet Saldanha <suneet@apache.org>
@zachjsh
zachjsh requested review from jasonk000 and suneet-s August 10, 2023 04:31

@suneet-s suneet-s left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after docs are added for the new metrics. Thanks @zachjsh !

@zachjsh

zachjsh commented Aug 10, 2023

Copy link
Copy Markdown
Contributor Author

LGTM after docs are added for the new metrics. Thanks @zachjsh !

thanks @suneet-s . Added the docs you requested. Wondering if the metric prefix should be changes from killTask to autoKillTask?

@zachjsh
zachjsh requested a review from suneet-s August 10, 2023 18:12

@jasonk000 jasonk000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved with a clarification/question

}

if (lastKillTime + period > currentTimeMillis) {
log.debug("Skipping kill of unused segments as kill period has not elapsed yet.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we check this twice (above, at line 117-119). Is it because we want to capture stats?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed thanks!

@suneet-s suneet-s left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a suggestion on changing the metric names to match the auto-compaction metric naming scheme a little better

Comment thread docs/operations/metrics.md Outdated
Comment thread server/src/main/java/org/apache/druid/server/coordinator/stats/Stats.java Outdated
@suneet-s

Copy link
Copy Markdown
Contributor

LGTM after docs are added for the new metrics. Thanks @zachjsh !

thanks @suneet-s . Added the docs you requested. Wondering if the metric prefix should be changes from killTask to autoKillTask?

I think killTask is fine as this matches the naming scheme of the auto-compaction metrics emitted by the CompactSegments duty

zachjsh and others added 2 commits August 10, 2023 15:28
Co-authored-by: Suneet Saldanha <suneet@apache.org>
@zachjsh
zachjsh merged commit 82d82df into apache:master Aug 10, 2023
@zachjsh
zachjsh deleted the auto-kill-stats branch August 10, 2023 22:36
@LakshSingla LakshSingla added this to the 28.0 milestone Oct 12, 2023
riovic918data pushed a commit to riovic918data/druid that referenced this pull request Jun 12, 2026
### Description

Added the following metrics, which are calculated from the `KillUnusedSegments` coordinatorDuty

`"killTask/availableSlot/count"`: calculates the number remaining task slots available for auto kill
`"killTask/maxSlot/count"`: calculates the maximum number of tasks available for auto kill
`"killTask/task/count"`: calculates the number of tasks submitted by auto kill. 

#### Release note
NEW: metrics added for auto kill

`"killTask/availableSlot/count"`: calculates the number remaining task slots available for auto kill
`"killTask/maxSlot/count"`: calculates the maximum number of tasks available for auto kill
`"killTask/task/count"`: calculates the number of tasks submitted by auto kill.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants