Skip to content

Commit 6fdc212

Browse files
authored
Consistently use ISO-8601 date time format (#2386)
* Consistently use ISO-8601 date time format * Adjust utils and WLST datetime generation * Match script and WLST datetime to operator
1 parent 1ae613e commit 6fdc212

File tree

11 files changed

+64
-77
lines changed

11 files changed

+64
-77
lines changed

kubernetes/samples/scripts/domain-lifecycle/README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ domain.weblogic.oracle/domain1 patched
8181
The `scaleCluster.sh` script scales a WebLogic cluster by patching the `spec.clusters[<cluster-name>].replicas` attribute of the domain resource to the specified value. The operator will perform the scaling operation for the WebLogic cluster based on the specified value of the `replicas` attribute after its value is updated. See the script `usage` information by using the `-h` option.
8282
```
8383
$ scaleCluster.sh -d domain1 -n weblogic-domain-1 -c cluster-1 -r 3
84-
[2021-02-26T19:04:14.335 UTC][INFO] Patching replicas for cluster 'cluster-1' to '3'.
84+
[2021-02-26T19:04:14.335000Z][INFO] Patching replicas for cluster 'cluster-1' to '3'.
8585
domain.weblogic.oracle/domain1 patched
86-
[2021-02-26T19:04:14.466 UTC][INFO] Successfully patched replicas for cluster 'cluster-1'!
86+
[2021-02-26T19:04:14.466000Z][INFO] Successfully patched replicas for cluster 'cluster-1'!
8787
```
8888

8989
### Script to view the status of a WebLogic cluster
@@ -123,42 +123,42 @@ The `rollDomain.sh` script updates the value of the `spec.restartVersion` attrib
123123

124124
```
125125
$ rollDomain.sh -d domain1 -n weblogic-domain-1
126-
[2021-03-24T04:01:19.733 UTC][INFO] Patching restartVersion for domain 'domain1' to '1'.
126+
[2021-03-24T04:01:19.733000Z][INFO] Patching restartVersion for domain 'domain1' to '1'.
127127
domain.weblogic.oracle/domain1 patched
128-
[2021-03-24T04:01:19.850 UTC][INFO] Successfully patched restartVersion for domain 'domain1'!
128+
[2021-03-24T04:01:19.850000Z][INFO] Successfully patched restartVersion for domain 'domain1'!
129129
```
130130

131131
Use the following command to roll the Server Pods in a WebLogic domain with a specific `restartVersion`:
132132
```
133133
$ rollDomain.sh -r v1 -d domain1 -n weblogic-domain-1
134-
[2021-03-24T13:43:47.586 UTC][INFO] Patching restartVersion for domain 'domain1' to 'v1'.
134+
[2021-03-24T13:43:47.586000Z][INFO] Patching restartVersion for domain 'domain1' to 'v1'.
135135
domain.weblogic.oracle/domain1 patched
136-
[2021-03-24T13:43:47.708 UTC][INFO] Successfully patched restartVersion for domain 'domain1'!
136+
[2021-03-24T13:43:47.708000Z][INFO] Successfully patched restartVersion for domain 'domain1'!
137137
```
138138

139139
The `rollCluster.sh` script updates the value of the `spec.clusters[<cluster-name>].restartVersion` attribute of the domain resource. Then, the operator will do a rolling restart of the WebLogic cluster Server Pods after the value of the `spec.clusters[<cluster-name>].restartVersion` is updated. You can provide the new value of the `restartVersion` as a parameter to the script or the script will automatically generate a new value to trigger the rolling restart. See the script `usage` information by using the `-h` option.
140140

141141
```
142142
$ rollCluster.sh -c cluster-1 -d domain1 -n weblogic-domain-1
143-
[2021-03-24T04:03:27.521 UTC][INFO] Patching restartVersion for cluster 'cluster-1' to '2'.
143+
[2021-03-24T04:03:27.521000Z][INFO] Patching restartVersion for cluster 'cluster-1' to '2'.
144144
domain.weblogic.oracle/domain1 patched
145-
[2021-03-24T04:03:27.669 UTC][INFO] Successfully patched restartVersion for cluster 'cluster-1'!
145+
[2021-03-24T04:03:27.669000Z][INFO] Successfully patched restartVersion for cluster 'cluster-1'!
146146
```
147147

148148
Use the following command to roll the WebLogic Cluster Servers with a specific `restartVersion`:
149149
```
150150
$ rollCluster.sh -r v2 -c cluster-1 -d domain1 -n weblogic-domain-1
151-
[2021-03-24T13:46:16.833 UTC][INFO] Patching restartVersion for cluster 'cluster-1' to 'v2'.
151+
[2021-03-24T13:46:16.833000Z][INFO] Patching restartVersion for cluster 'cluster-1' to 'v2'.
152152
domain.weblogic.oracle/domain1 patched
153-
[2021-03-24T13:46:16.975 UTC][INFO] Successfully patched restartVersion for cluster 'cluster-1'!
153+
[2021-03-24T13:46:16.975000Z][INFO] Successfully patched restartVersion for cluster 'cluster-1'!
154154
```
155155

156156
### Scripts to restart a WebLogic Server in a domain
157157
The `restartServer.sh` script can be used to restart a WebLogic Server in a domain. This script restarts the Server by deleting the Server Pod for the WebLogic Server instance.
158158
```
159159
$ restartServer.sh -s managed-server1 -d domain1 -n weblogic-domain-1
160-
[2021-03-24T22:20:22.498 UTC][INFO] Initiating restart of 'managed-server1' by deleting server pod 'domain1-managed-server1'.
161-
[2021-03-24T22:20:37.614 UTC][INFO] Server restart succeeded !
160+
[2021-03-24T22:20:22.498000Z][INFO] Initiating restart of 'managed-server1' by deleting server pod 'domain1-managed-server1'.
161+
[2021-03-24T22:20:37.614000Z][INFO] Server restart succeeded !
162162
```
163163

164164
### Scripts to explicitly initiate introspection of a WebLogic domain
@@ -168,17 +168,17 @@ The `introspectDomain.sh` script can be used to rerun a WebLogic domain's intros
168168
Use the following command to rerun a domain's introspect job with the `introspectVersion` value generated by the script.
169169
```
170170
$ introspectDomain.sh -d domain1 -n weblogic-domain-1
171-
[2021-03-24T21:37:55.989 UTC][INFO] Patching introspectVersion for domain 'domain1' to '1'.
171+
[2021-03-24T21:37:55.989000Z][INFO] Patching introspectVersion for domain 'domain1' to '1'.
172172
domain.weblogic.oracle/domain1 patched
173-
[2021-03-24T21:37:56.110 UTC][INFO] Successfully patched introspectVersion for domain 'domain1'!
173+
[2021-03-24T21:37:56.110000Z][INFO] Successfully patched introspectVersion for domain 'domain1'!
174174
```
175175

176176
Use the following command to rerun a domain's introspect job with a specific `introspectVersion` value.
177177
```
178178
$ introspectDomain.sh -i v1 -d domain1 -n weblogic-domain-1
179-
[2021-03-24T21:38:34.369 UTC][INFO] Patching introspectVersion for domain 'domain1' to 'v1'.
179+
[2021-03-24T21:38:34.369000Z][INFO] Patching introspectVersion for domain 'domain1' to 'v1'.
180180
domain.weblogic.oracle/domain1 patched
181-
[2021-03-24T21:38:34.488 UTC][INFO] Successfully patched introspectVersion for domain 'domain1'!
181+
[2021-03-24T21:38:34.488000Z][INFO] Successfully patched introspectVersion for domain 'domain1'!
182182
```
183183

184184
### Watching the Pods after executing life cycle scripts

kubernetes/samples/scripts/domain-lifecycle/helper.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,19 +1006,15 @@ function executePatchCommand {
10061006
}
10071007

10081008
# timestamp
1009-
# purpose: echo timestamp in the form yyyymmddThh:mm:ss.mmm ZZZ
1010-
# example: 20181001T14:00:00.001 UTC
1009+
# purpose: echo timestamp in the form yyyy-mm-ddThh:mm:ss.nnnnnnZ
1010+
# example: 2018-10-01T14:00:00.000001Z
10111011
function timestamp() {
1012-
timestamp="$(set +e && date --utc '+%Y-%m-%dT%H:%M:%S %N %s %Z' 2>&1 || echo illegal)"
1012+
local timestamp="`date --utc '+%Y-%m-%dT%H:%M:%S.%NZ' 2>&1`"
10131013
if [ ! "${timestamp/illegal/xyz}" = "${timestamp}" ]; then
10141014
# old shell versions don't support %N or --utc
1015-
timestamp="`date -u '+%Y-%m-%dT%H:%M:%S 000000 %s %Z' 2>&1`"
1015+
timestamp="`date -u '+%Y-%m-%dT%H:%M:%S.000000Z' 2>&1`"
10161016
fi
1017-
local ymdhms="`echo $timestamp | awk '{ print $1 }'`"
1018-
# convert nano to milli
1019-
local milli="`echo $timestamp | awk '{ print $2 }' | sed 's/\(^...\).*/\1/'`"
1020-
local timezone="`echo $timestamp | awk '{ print $4 }'`"
1021-
echo "${ymdhms}.${milli} ${timezone}"
1017+
echo "${timestamp}"
10221018
}
10231019

10241020
#

operator/scripts/scaling/scalingAction.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,15 @@ kubernetes_master="https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}
1717
log_file_name="scalingAction.log"
1818

1919
# timestamp
20-
# purpose: echo timestamp in the form yyyymmddThh:mm:ss.mmm ZZZ
21-
# example: 20181001T14:00:00.001 UTC
20+
# purpose: echo timestamp in the form yyyy-mm-ddThh:mm:ss.nnnnnnZ
21+
# example: 2018-10-01T14:00:00.000001Z
2222
function timestamp() {
23-
local timestamp="`date --utc '+%Y-%m-%dT%H:%M:%S %N %s %Z' 2>&1`"
23+
local timestamp="`date --utc '+%Y-%m-%dT%H:%M:%S.%NZ' 2>&1`"
2424
if [ ! "${timestamp/illegal/xyz}" = "${timestamp}" ]; then
2525
# old shell versions don't support %N or --utc
26-
timestamp="`date -u '+%Y-%m-%dT%H:%M:%S 000000 %s %Z' 2>&1`"
26+
timestamp="`date -u '+%Y-%m-%dT%H:%M:%S.000000Z' 2>&1`"
2727
fi
28-
local ymdhms="`echo $timestamp | awk '{ print $1 }'`"
29-
# convert nano to milli
30-
local milli="`echo $timestamp | awk '{ print $2 }' | sed 's/\(^...\).*/\1/'`"
31-
local timezone="`echo $timestamp | awk '{ print $4 }'`"
32-
echo "${ymdhms}.${milli} ${timezone}"
28+
echo "${timestamp}"
3329
}
3430

3531
function trace() {

operator/src/main/java/oracle/kubernetes/operator/logging/LoggingFormatter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
import java.io.PrintWriter;
77
import java.io.StringWriter;
8-
import java.text.SimpleDateFormat;
9-
import java.util.Date;
8+
import java.time.OffsetDateTime;
9+
import java.time.ZoneId;
10+
import java.time.format.DateTimeFormatter;
1011
import java.util.HashMap;
1112
import java.util.LinkedHashMap;
1213
import java.util.List;
@@ -39,14 +40,13 @@ public class LoggingFormatter extends Formatter {
3940
private static final String TIME_IN_MILLIS = "timeInMillis";
4041
private static final String MESSAGE = "message";
4142
private static final String EXCEPTION = "exception";
42-
private static final String DATE_FORMAT = "MM-dd-yyyy'T'HH:mm:ss.SSSZZ";
4343

4444
// For ApiException
4545
private static final String RESPONSE_CODE = "code";
4646
private static final String RESPONSE_HEADERS = "headers";
4747
private static final String RESPONSE_BODY = "body";
4848

49-
private final SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
49+
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
5050

5151
@Override
5252
public String format(LogRecord record) {
@@ -107,7 +107,7 @@ public String format(LogRecord record) {
107107
String level = record.getLevel().getLocalizedName();
108108
Map<String, Object> map = new LinkedHashMap<>();
109109
long rawTime = record.getMillis();
110-
final String dateString = dateFormat.format(new Date(rawTime));
110+
final String dateString = DATE_FORMAT.format(OffsetDateTime.ofInstant(record.getInstant(), ZoneId.systemDefault()));
111111
long thread = Thread.currentThread().getId();
112112
Fiber fiber = Fiber.getCurrentIfSet();
113113

operator/src/main/java/oracle/kubernetes/operator/rest/BaseDebugLoggingFilter.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
package oracle.kubernetes.operator.rest;
55

6-
import java.text.SimpleDateFormat;
6+
import java.time.format.DateTimeFormatter;
7+
import java.time.temporal.TemporalAccessor;
78
import java.util.ArrayList;
8-
import java.util.Date;
99
import java.util.List;
1010

1111
import jakarta.ws.rs.container.ContainerRequestContext;
@@ -24,12 +24,10 @@ public abstract class BaseDebugLoggingFilter {
2424
protected static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
2525
protected static final String FILTER_REQUEST_START_TIME = "FILTER_REQUEST_START_TIME";
2626
protected static final String FILTER_REQUEST_ENTITY = "FILTER_REQUEST_ENTITY";
27-
private static final String DATE_FORMAT =
28-
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"; // ISO 8610, includes time zone
27+
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
2928

30-
protected static String formatTime(long time) {
31-
// construct a new SimpleDataFormat each time since it is not thread safe:
32-
return new SimpleDateFormat(DATE_FORMAT).format(new Date(time));
29+
protected static String formatTime(TemporalAccessor time) {
30+
return DATE_FORMAT.format(time);
3331
}
3432

3533
protected String formatEntity(MediaType type, String entityAsString) {

operator/src/main/java/oracle/kubernetes/operator/rest/RequestDebugLoggingFilter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.ByteArrayInputStream;
88
import java.io.InputStreamReader;
99
import java.nio.charset.Charset;
10+
import java.time.OffsetDateTime;
1011
import javax.annotation.Priority;
1112

1213
import jakarta.ws.rs.container.ContainerRequestContext;
@@ -38,7 +39,7 @@ public void filter(ContainerRequestContext req) {
3839
try {
3940
// cache the start time and request body so that the response filter
4041
// can log them too
41-
long start = System.currentTimeMillis();
42+
OffsetDateTime start = OffsetDateTime.now();
4243
req.setProperty(FILTER_REQUEST_START_TIME, start);
4344
Object reqEntity = getRequestEntity(req);
4445
if (reqEntity != null) {

operator/src/main/java/oracle/kubernetes/operator/rest/ResponseDebugLoggingFilter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package oracle.kubernetes.operator.rest;
55

66
import java.io.InputStream;
7+
import java.time.OffsetDateTime;
8+
import java.time.temporal.ChronoUnit;
79
import javax.annotation.Priority;
810

911
import jakarta.ws.rs.container.ContainerRequestContext;
@@ -38,9 +40,9 @@ public void filter(ContainerRequestContext req, ContainerResponseContext res) {
3840
LOGGER.fine("method=" + req.getMethod());
3941
Object prop = req.getProperty(FILTER_REQUEST_START_TIME);
4042
if (prop != null) {
41-
long start = (Long) prop;
42-
long end = System.currentTimeMillis();
43-
long duration = end - start;
43+
OffsetDateTime start = (OffsetDateTime) prop;
44+
OffsetDateTime end = OffsetDateTime.now();
45+
long duration = start.until(end, ChronoUnit.MILLIS);
4446
LOGGER.fine("start=" + formatTime(start));
4547
LOGGER.fine("duration=" + duration + " ms");
4648
}

operator/src/main/resources/scripts/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
# 'ERROR' is converted to 'SEVERE'
99
# Unknown logLevels are converted to 'FINE'.
1010
#
11-
# This matches format of bash utils.sh trace, and rougly matches the operator's log format.
11+
# This matches format of bash utils.sh trace and the operator's log format.
1212
#
13-
# Sample output: @[2018-09-28T17:23:55.335 UTC][introspectDomain.py:614][FINE] Domain introspection complete.
13+
# Sample output: @[2018-09-28T17:23:55.335000Z][introspectDomain.py:614][FINE] Domain introspection complete.
1414
#
1515
# Importing this file when it's not in sys.path of the calling script:
1616
#
@@ -52,8 +52,8 @@ def traceInner(logLevel,object):
5252
}
5353
# use FINE as logLevel if logLevel is not a known type
5454
logLevel=switcher.get(logLevel.upper(),'FINE')
55-
print("@[%d-%.2d-%.2dT%.2d:%.2d:%.2d.%.3d UTC][%s:%s][%s] %s"
56-
% (dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second,dt.microsecond/1000,
55+
print("@[%d-%.2d-%.2dT%.2d:%.2d:%.2d.%.6dZ][%s:%s][%s] %s"
56+
% (dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second,dt.microsecond,
5757
filename,lineno,logLevel,object))
5858

5959
def trace(arg1,arg2='SENTINEL'):

operator/src/main/resources/scripts/utils_base.sh

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@
3333
#
3434
# examples:
3535
# trace "Situation normal."
36-
# @[2018-09-28T18:10:52.417 UTC][myscript.sh:91][FINE] Situation normal.
36+
# @[2018-09-28T18:10:52.417000Z][myscript.sh:91][FINE] Situation normal.
3737
#
3838
# trace INFO "Situation normal."
39-
# @[2018-09-28T18:10:52.417 UTC][myscript.sh:91][INFO] Situation normal.
39+
# @[2018-09-28T18:10:52.417000Z][myscript.sh:91][INFO] Situation normal.
4040
#
4141
# trace "Info: Situation normal."
42-
# @[2018-09-28T18:10:52.417 UTC][myscript.sh:91][INFO] Info: Situation normal.
42+
# @[2018-09-28T18:10:52.417000Z][myscript.sh:91][INFO] Info: Situation normal.
4343
#
4444
# ls 2>&1 | tracePipe FINE "ls output: "
45-
# @[2018-09-28T18:10:52.417 UTC][myscript.sh:91][FINE] ls output: file1
46-
# @[2018-09-28T18:10:52.417 UTC][myscript.sh:91][FINE] ls output: file2
45+
# @[2018-09-28T18:10:52.417000Z][myscript.sh:91][FINE] ls output: file1
46+
# @[2018-09-28T18:10:52.417000Z][myscript.sh:91][FINE] ls output: file2
4747
#
4848
# Set TRACE_INCLUDE_FILE env var to false to suppress file name and line number.
4949
#
@@ -167,21 +167,15 @@ function traceDirs() {
167167
}
168168

169169
# timestamp
170-
# purpose: echo timestamp in the form yyyymmddThh:mm:ss.mmm ZZZ
171-
# example: 20181001T14:00:00.001 UTC
170+
# purpose: echo timestamp in the form yyyy-mm-ddThh:mm:ss.nnnnnnZ
171+
# example: 2018-10-01T14:00:00.000001Z
172172
function timestamp() {
173-
local timestamp="`date --utc '+%Y-%m-%dT%H:%M:%S %N %s %Z' 2>&1`"
173+
local timestamp="`date --utc '+%Y-%m-%dT%H:%M:%S.%NZ' 2>&1`"
174174
if [ ! "${timestamp/illegal/xyz}" = "${timestamp}" ]; then
175175
# old shell versions don't support %N or --utc
176-
timestamp="`date -u '+%Y-%m-%dT%H:%M:%S 000000 %s %Z' 2>&1`"
176+
timestamp="`date -u '+%Y-%m-%dT%H:%M:%S.000000Z' 2>&1`"
177177
fi
178-
local ymdhms="`echo $timestamp | awk '{ print $1 }'`"
179-
# convert nano to milli
180-
local milli="`echo $timestamp | awk '{ print $2 }' | sed 's/\(^...\).*/\1/'`"
181-
local secs_since_epoch="`echo $timestamp | awk '{ print $3 }'`"
182-
local millis_since_opoch="${secs_since_epoch}${milli}"
183-
local timezone="`echo $timestamp | awk '{ print $4 }'`"
184-
echo "${ymdhms}.${milli} ${timezone}"
178+
echo "${timestamp}"
185179
}
186180

187181
#
@@ -193,9 +187,9 @@ function timestamp() {
193187
# (Pass '-q' to suppress FINE tracing.)
194188
#
195189
# sample: checkEnv HOST NOTSET1 USER NOTSET2
196-
# @[2018-10-05T22:48:04.368 UTC][FINE] HOST='esscupcakes'
197-
# @[2018-10-05T22:48:04.393 UTC][FINE] USER='friendly'
198-
# @[2018-10-05T22:48:04.415 UTC][SEVERE] The following env vars are missing or empty: NOTSET1 NOTSET2
190+
# @[2018-10-05T22:48:04.368000Z][FINE] HOST='esscupcakes'
191+
# @[2018-10-05T22:48:04.393000Z][FINE] USER='friendly'
192+
# @[2018-10-05T22:48:04.415000Z][SEVERE] The following env vars are missing or empty: NOTSET1 NOTSET2
199193
#
200194
function checkEnv() {
201195
local do_fine="true"

operator/src/test/java/oracle/kubernetes/operator/DomainProcessorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ private void getMIIOnlineUpdateIntrospectResult(DomainConditionType domainCondit
10451045
+ "\n"
10461046
+ ">>> EOF\n"
10471047
+ "\n"
1048-
+ "@[2018-10-04T21:07:06.864 UTC][introspectDomain.py:105] Printing file "
1048+
+ "@[2018-10-04T21:07:06.864000Z][introspectDomain.py:105] Printing file "
10491049
+ "/u01/introspect/domain1/userKeyNodeManager.secure\n"
10501050
+ "\n"
10511051
+ ">>> /u01/introspect/domain1/userKeyNodeManager.secure\n"
@@ -1058,7 +1058,7 @@ private void getMIIOnlineUpdateIntrospectResult(DomainConditionType domainCondit
10581058
+ "\n"
10591059
+ ">>> EOF\n"
10601060
+ "\n"
1061-
+ "@[2018-10-04T21:07:06.867 UTC][introspectDomain.py:105] Printing file "
1061+
+ "@[2018-10-04T21:07:06.867000Z][introspectDomain.py:105] Printing file "
10621062
+ "/u01/introspect/domain1/topology.yaml\n"
10631063
+ "\n"
10641064
+ ">>> /u01/introspect/domain1/topology.yaml\n"

0 commit comments

Comments
 (0)