Skip to content
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

Fixes eventlogger timestamp format #1569

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -40,13 +40,7 @@ public MutablePair<CoreV1Event, V1Patch> observe(CoreV1Event event, String key)
event.getMetadata().setName(lastObserved.name);
event.getMetadata().setResourceVersion(lastObserved.resourceVersion);

patch =
new V1Patch(
String.format(
"{\"message\":\"%s\",\"count\":%d,\"lastTimestamp\":\"%s\"}",
event.getMessage(),
event.getCount(),
Configuration.getDefaultApiClient().getJSON().serialize(now)));
patch = buildEventPatch(event.getCount(), event.getMessage(), now);
}
EventLog log = new EventLog();
log.count = event.getCount();
Expand All @@ -73,4 +67,11 @@ private static class EventLog {
private String name;
private String resourceVersion;
}

static V1Patch buildEventPatch(int count, String message, OffsetDateTime now) {
return new V1Patch(
String.format(
"{\"message\":\"%s\",\"count\":%d,\"lastTimestamp\":%s}",
message, count, Configuration.getDefaultApiClient().getJSON().serialize(now)));
}
}
@@ -0,0 +1,32 @@
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package io.kubernetes.client.extended.event.legacy;

import static org.junit.Assert.*;

import io.kubernetes.client.custom.V1Patch;
import java.time.OffsetDateTime;
import org.junit.Test;

public class EventLoggerTest {

@Test
public void buildEventPatch() {
String expectedStr = "2021-03-02T15:02:48.179000Z";
OffsetDateTime expected = OffsetDateTime.parse("2021-03-02T15:02:48.179000Z");
V1Patch patch = EventLogger.buildEventPatch(1, "foo", expected);
assertEquals(
"{\"message\":\"foo\",\"count\":1,\"lastTimestamp\":\"" + expectedStr + "\"}",
patch.getValue());
}
}