Skip to content

Commit af0a2a0

Browse files
authored
Fix log formatting in SnapshotLifecycleTask (elastic#136709) (elastic#136756)
While converting an error log from `logger.error` to `logger.error(format())` in elastic#131646, we forgot to update the syntax from `{}` to `%s`. This resulted in the logs `failed to create snapshot for snapshot lifecycle policy [{}]`. This commit fixes the syntax and ensures we use the right logger.
1 parent 95aff8e commit af0a2a0

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

docs/changelog/136709.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 136709
2+
summary: Fix log formatting in `SnapshotLifecycleTask`
3+
area: ILM+SLM
4+
type: bug
5+
issues: []

x-pack/plugin/slm/src/main/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,9 @@ public void onFailure(Exception e) {
265265
@Override
266266
public void onFailure(Exception e) {
267267
SnapshotHistoryStore.logErrorOrWarning(
268+
logger,
268269
clusterService.state(),
269-
() -> format("failed to create snapshot for snapshot lifecycle policy [{}]", policyMetadata.getPolicy().getId()),
270+
() -> format("failed to create snapshot for snapshot lifecycle policy [%s]", policyMetadata.getPolicy().getId()),
270271
e
271272
);
272273
final long timestamp = Instant.now().toEpochMilli();

x-pack/plugin/slm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStore.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ public void putAsync(SnapshotHistoryItem item) {
8888
);
8989
},
9090
exception -> logErrorOrWarning(
91+
logger,
9192
clusterService.state(),
9293
() -> format("failed to index snapshot history item in data stream [%s]: [%s]", SLM_HISTORY_DATA_STREAM, item),
9394
exception
9495
)
9596
));
9697
} catch (IOException exception) {
9798
logErrorOrWarning(
99+
logger,
98100
clusterService.state(),
99101
() -> format("failed to index snapshot history item in data stream [%s]: [%s]", SLM_HISTORY_DATA_STREAM, item),
100102
exception
@@ -103,7 +105,7 @@ public void putAsync(SnapshotHistoryItem item) {
103105
}
104106

105107
// On node shutdown, some operations are expected to fail, we log a warning instead of error during node shutdown for those exceptions
106-
public static void logErrorOrWarning(ClusterState clusterState, Supplier<?> failureMsgSupplier, Exception exception) {
108+
public static void logErrorOrWarning(Logger logger, ClusterState clusterState, Supplier<?> failureMsgSupplier, Exception exception) {
107109
if (PluginShutdownService.isLocalNodeShutdown(clusterState)) {
108110
logger.warn(failureMsgSupplier, exception);
109111
} else {

0 commit comments

Comments
 (0)