Skip to content

Commit 3ed549b

Browse files
authored
TSDB: RollupShardIndexer logging improvements (#88416)
1. Add trace log guards to avoid high cost method 2. Log the time it took to rollup a shard
1 parent 24d2520 commit 3ed549b

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/v2/RollupShardIndexer.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class RollupShardIndexer {
127127
}
128128

129129
public RollupIndexerAction.ShardRollupResponse execute() throws IOException {
130+
long startTime = System.currentTimeMillis();
130131
BulkProcessor bulkProcessor = createBulkProcessor();
131132
try (searcher; bulkProcessor) {
132133
// TODO: add cancellations
@@ -138,11 +139,12 @@ public RollupIndexerAction.ShardRollupResponse execute() throws IOException {
138139
}
139140

140141
logger.info(
141-
"Shard {} successfully sent [{}], indexed [{}], failed [{}]",
142+
"Shard [{}] successfully sent [{}], indexed [{}], failed [{}], took [{}]",
142143
indexShard.shardId(),
143144
numSent.get(),
144145
numIndexed.get(),
145-
numFailed.get()
146+
numFailed.get(),
147+
TimeValue.timeValueMillis(System.currentTimeMillis() - startTime)
146148
);
147149

148150
if (numIndexed.get() != numSent.get()) {
@@ -239,13 +241,15 @@ public void collect(int docId, long owningBucketOrd) throws IOException {
239241
lastHistoTimestamp = rounding.round(timestamp);
240242
}
241243

242-
logger.trace(
243-
"Doc: [{}] - _tsid: [{}], @timestamp: [{}}] -> rollup bucket ts: [{}]",
244-
docId,
245-
DocValueFormat.TIME_SERIES_ID.format(tsid),
246-
timestampFormat.format(timestamp),
247-
timestampFormat.format(lastHistoTimestamp)
248-
);
244+
if (logger.isTraceEnabled()) {
245+
logger.trace(
246+
"Doc: [{}] - _tsid: [{}], @timestamp: [{}}] -> rollup bucket ts: [{}]",
247+
docId,
248+
DocValueFormat.TIME_SERIES_ID.format(tsid),
249+
timestampFormat.format(timestamp),
250+
timestampFormat.format(lastHistoTimestamp)
251+
);
252+
}
249253

250254
/*
251255
* Sanity checks to ensure that we receive documents in the correct order
@@ -349,11 +353,14 @@ public RollupBucketBuilder init(BytesRef tsid, long timestamp) {
349353
this.timestamp = timestamp;
350354
this.docCount = 0;
351355
this.metricFieldProducers.values().stream().forEach(p -> p.reset());
352-
logger.trace(
353-
"New bucket for _tsid: [{}], @timestamp: [{}]",
354-
DocValueFormat.TIME_SERIES_ID.format(tsid),
355-
timestampFormat.format(timestamp)
356-
);
356+
if (logger.isTraceEnabled()) {
357+
logger.trace(
358+
"New bucket for _tsid: [{}], @timestamp: [{}]",
359+
DocValueFormat.TIME_SERIES_ID.format(tsid),
360+
timestampFormat.format(timestamp)
361+
);
362+
}
363+
357364
return this;
358365
}
359366

0 commit comments

Comments
 (0)