Skip to content

Consistently use ISO-8601 date time format #2386

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

Merged
merged 7 commits into from
Jun 2, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions kubernetes/samples/scripts/domain-lifecycle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ domain.weblogic.oracle/domain1 patched
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.
```
$ scaleCluster.sh -d domain1 -n weblogic-domain-1 -c cluster-1 -r 3
[2021-02-26T19:04:14.335 UTC][INFO] Patching replicas for cluster 'cluster-1' to '3'.
[2021-02-26T19:04:14.335000Z][INFO] Patching replicas for cluster 'cluster-1' to '3'.
domain.weblogic.oracle/domain1 patched
[2021-02-26T19:04:14.466 UTC][INFO] Successfully patched replicas for cluster 'cluster-1'!
[2021-02-26T19:04:14.466000Z][INFO] Successfully patched replicas for cluster 'cluster-1'!
```

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

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

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

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.

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

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

### Scripts to restart a WebLogic Server in a domain
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.
```
$ restartServer.sh -s managed-server1 -d domain1 -n weblogic-domain-1
[2021-03-24T22:20:22.498 UTC][INFO] Initiating restart of 'managed-server1' by deleting server pod 'domain1-managed-server1'.
[2021-03-24T22:20:37.614 UTC][INFO] Server restart succeeded !
[2021-03-24T22:20:22.498000Z][INFO] Initiating restart of 'managed-server1' by deleting server pod 'domain1-managed-server1'.
[2021-03-24T22:20:37.614000Z][INFO] Server restart succeeded !
```

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

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

### Watching the Pods after executing life cycle scripts
Expand Down
14 changes: 5 additions & 9 deletions kubernetes/samples/scripts/domain-lifecycle/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1006,19 +1006,15 @@ function executePatchCommand {
}

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

#
Expand Down
14 changes: 5 additions & 9 deletions operator/scripts/scaling/scalingAction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@ kubernetes_master="https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}
log_file_name="scalingAction.log"

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

function trace() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -39,14 +40,13 @@ public class LoggingFormatter extends Formatter {
private static final String TIME_IN_MILLIS = "timeInMillis";
private static final String MESSAGE = "message";
private static final String EXCEPTION = "exception";
private static final String DATE_FORMAT = "MM-dd-yyyy'T'HH:mm:ss.SSSZZ";

// For ApiException
private static final String RESPONSE_CODE = "code";
private static final String RESPONSE_HEADERS = "headers";
private static final String RESPONSE_BODY = "body";

private final SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ISO_OFFSET_DATE_TIME;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

package oracle.kubernetes.operator.rest;

import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

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

protected static String formatTime(long time) {
// construct a new SimpleDataFormat each time since it is not thread safe:
return new SimpleDateFormat(DATE_FORMAT).format(new Date(time));
protected static String formatTime(TemporalAccessor time) {
return DATE_FORMAT.format(time);
}

protected String formatEntity(MediaType type, String entityAsString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.time.OffsetDateTime;
import javax.annotation.Priority;

import jakarta.ws.rs.container.ContainerRequestContext;
Expand Down Expand Up @@ -38,7 +39,7 @@ public void filter(ContainerRequestContext req) {
try {
// cache the start time and request body so that the response filter
// can log them too
long start = System.currentTimeMillis();
OffsetDateTime start = OffsetDateTime.now();
req.setProperty(FILTER_REQUEST_START_TIME, start);
Object reqEntity = getRequestEntity(req);
if (reqEntity != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package oracle.kubernetes.operator.rest;

import java.io.InputStream;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import javax.annotation.Priority;

import jakarta.ws.rs.container.ContainerRequestContext;
Expand Down Expand Up @@ -38,9 +40,9 @@ public void filter(ContainerRequestContext req, ContainerResponseContext res) {
LOGGER.fine("method=" + req.getMethod());
Object prop = req.getProperty(FILTER_REQUEST_START_TIME);
if (prop != null) {
long start = (Long) prop;
long end = System.currentTimeMillis();
long duration = end - start;
OffsetDateTime start = (OffsetDateTime) prop;
OffsetDateTime end = OffsetDateTime.now();
long duration = start.until(end, ChronoUnit.MILLIS);
LOGGER.fine("start=" + formatTime(start));
LOGGER.fine("duration=" + duration + " ms");
}
Expand Down
8 changes: 4 additions & 4 deletions operator/src/main/resources/scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
# 'ERROR' is converted to 'SEVERE'
# Unknown logLevels are converted to 'FINE'.
#
# This matches format of bash utils.sh trace, and rougly matches the operator's log format.
# This matches format of bash utils.sh trace and the operator's log format.
#
# Sample output: @[2018-09-28T17:23:55.335 UTC][introspectDomain.py:614][FINE] Domain introspection complete.
# Sample output: @[2018-09-28T17:23:55.335000Z][introspectDomain.py:614][FINE] Domain introspection complete.
#
# Importing this file when it's not in sys.path of the calling script:
#
Expand Down Expand Up @@ -52,8 +52,8 @@ def traceInner(logLevel,object):
}
# use FINE as logLevel if logLevel is not a known type
logLevel=switcher.get(logLevel.upper(),'FINE')
print("@[%d-%.2d-%.2dT%.2d:%.2d:%.2d.%.3d UTC][%s:%s][%s] %s"
% (dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second,dt.microsecond/1000,
print("@[%d-%.2d-%.2dT%.2d:%.2d:%.2d.%.6dZ][%s:%s][%s] %s"
% (dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second,dt.microsecond,
filename,lineno,logLevel,object))

def trace(arg1,arg2='SENTINEL'):
Expand Down
32 changes: 13 additions & 19 deletions operator/src/main/resources/scripts/utils_base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
#
# examples:
# trace "Situation normal."
# @[2018-09-28T18:10:52.417 UTC][myscript.sh:91][FINE] Situation normal.
# @[2018-09-28T18:10:52.417000Z][myscript.sh:91][FINE] Situation normal.
#
# trace INFO "Situation normal."
# @[2018-09-28T18:10:52.417 UTC][myscript.sh:91][INFO] Situation normal.
# @[2018-09-28T18:10:52.417000Z][myscript.sh:91][INFO] Situation normal.
#
# trace "Info: Situation normal."
# @[2018-09-28T18:10:52.417 UTC][myscript.sh:91][INFO] Info: Situation normal.
# @[2018-09-28T18:10:52.417000Z][myscript.sh:91][INFO] Info: Situation normal.
#
# ls 2>&1 | tracePipe FINE "ls output: "
# @[2018-09-28T18:10:52.417 UTC][myscript.sh:91][FINE] ls output: file1
# @[2018-09-28T18:10:52.417 UTC][myscript.sh:91][FINE] ls output: file2
# @[2018-09-28T18:10:52.417000Z][myscript.sh:91][FINE] ls output: file1
# @[2018-09-28T18:10:52.417000Z][myscript.sh:91][FINE] ls output: file2
#
# Set TRACE_INCLUDE_FILE env var to false to suppress file name and line number.
#
Expand Down Expand Up @@ -167,21 +167,15 @@ function traceDirs() {
}

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

#
Expand All @@ -193,9 +187,9 @@ function timestamp() {
# (Pass '-q' to suppress FINE tracing.)
#
# sample: checkEnv HOST NOTSET1 USER NOTSET2
# @[2018-10-05T22:48:04.368 UTC][FINE] HOST='esscupcakes'
# @[2018-10-05T22:48:04.393 UTC][FINE] USER='friendly'
# @[2018-10-05T22:48:04.415 UTC][SEVERE] The following env vars are missing or empty: NOTSET1 NOTSET2
# @[2018-10-05T22:48:04.368000Z][FINE] HOST='esscupcakes'
# @[2018-10-05T22:48:04.393000Z][FINE] USER='friendly'
# @[2018-10-05T22:48:04.415000Z][SEVERE] The following env vars are missing or empty: NOTSET1 NOTSET2
#
function checkEnv() {
local do_fine="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ private void getMIIOnlineUpdateIntrospectResult(DomainConditionType domainCondit
+ "\n"
+ ">>> EOF\n"
+ "\n"
+ "@[2018-10-04T21:07:06.864 UTC][introspectDomain.py:105] Printing file "
+ "@[2018-10-04T21:07:06.864000Z][introspectDomain.py:105] Printing file "
+ "/u01/introspect/domain1/userKeyNodeManager.secure\n"
+ "\n"
+ ">>> /u01/introspect/domain1/userKeyNodeManager.secure\n"
Expand All @@ -1058,7 +1058,7 @@ private void getMIIOnlineUpdateIntrospectResult(DomainConditionType domainCondit
+ "\n"
+ ">>> EOF\n"
+ "\n"
+ "@[2018-10-04T21:07:06.867 UTC][introspectDomain.py:105] Printing file "
+ "@[2018-10-04T21:07:06.867000Z][introspectDomain.py:105] Printing file "
+ "/u01/introspect/domain1/topology.yaml\n"
+ "\n"
+ ">>> /u01/introspect/domain1/topology.yaml\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public class IntrospectionTestUtils {
+ "\n"
+ ">>> EOF\n"
+ "\n"
+ "@[2018-10-04T21:07:06.864 UTC][introspectDomain.py:105] Printing file "
+ "@[2018-10-04T21:07:06.864000Z][introspectDomain.py:105] Printing file "
+ "/u01/introspect/domain1/userKeyNodeManager.secure\n"
+ "\n"
+ ">>> /u01/introspect/domain1/userKeyNodeManager.secure\n"
+ "BPtNabkCIIc2IJp/TzZ9TzbUHG7O3xboteDytDO3XnwNhumdSpaUGKmcbusdmbOUY+4J2kteu6xJPWTzmNRAtg==\n"
+ "\n"
+ ">>> EOF\n"
+ "\n"
+ "@[2018-10-04T21:07:06.867 UTC][introspectDomain.py:105] Printing file "
+ "@[2018-10-04T21:07:06.867000Z][introspectDomain.py:105] Printing file "
+ "/u01/introspect/domain1/topology.yaml\n"
+ "\n"
+ ">>> /u01/introspect/domain1/topology.yaml\n"
Expand Down