Skip to content

Commit a10b0bd

Browse files
committed
fixes eventlogger timestamp format
1 parent 6b793f5 commit a10b0bd

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

extended/src/main/java/io/kubernetes/client/extended/event/legacy/EventLogger.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,7 @@ public MutablePair<CoreV1Event, V1Patch> observe(CoreV1Event event, String key)
4040
event.getMetadata().setName(lastObserved.name);
4141
event.getMetadata().setResourceVersion(lastObserved.resourceVersion);
4242

43-
patch =
44-
new V1Patch(
45-
String.format(
46-
"{\"message\":\"%s\",\"count\":%d,\"lastTimestamp\":\"%s\"}",
47-
event.getMessage(),
48-
event.getCount(),
49-
Configuration.getDefaultApiClient().getJSON().serialize(now)));
43+
patch = buildEventPatch(event.getCount(), event.getMessage(), now);
5044
}
5145
EventLog log = new EventLog();
5246
log.count = event.getCount();
@@ -73,4 +67,11 @@ private static class EventLog {
7367
private String name;
7468
private String resourceVersion;
7569
}
70+
71+
static V1Patch buildEventPatch(int count, String message, OffsetDateTime now) {
72+
return new V1Patch(
73+
String.format(
74+
"{\"message\":\"%s\",\"count\":%d,\"lastTimestamp\":%s}",
75+
message, count, Configuration.getDefaultApiClient().getJSON().serialize(now)));
76+
}
7677
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
package io.kubernetes.client.extended.event.legacy;
14+
15+
import static org.junit.Assert.*;
16+
17+
import io.kubernetes.client.custom.V1Patch;
18+
import java.time.OffsetDateTime;
19+
import org.junit.Test;
20+
21+
public class EventLoggerTest {
22+
23+
@Test
24+
public void buildEventPatch() {
25+
String expectedStr = "2021-03-02T15:02:48.179000Z";
26+
OffsetDateTime expected = OffsetDateTime.parse("2021-03-02T15:02:48.179000Z");
27+
V1Patch patch = EventLogger.buildEventPatch(1, "foo", expected);
28+
assertEquals(
29+
"{\"message\":\"foo\",\"count\":1,\"lastTimestamp\":\"" + expectedStr + "\"}",
30+
patch.getValue());
31+
}
32+
}

0 commit comments

Comments
 (0)