Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Add RFC3339 timestamp to log link generation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fg91 committed Jun 13, 2023
1 parent b4e2372 commit 0331ba7
Showing 1 changed file with 94 additions and 49 deletions.
143 changes: 94 additions & 49 deletions go/tasks/pluginmachinery/tasklog/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func TestTemplateLog(t *testing.T) {
"spark-kubernetes-driver",
"cri-o://abc",
"main_logs",
"2015-03-14T17:08:14+01:00",
"2021-06-15T20:47:57+02:00",
1426349294,
1623782877,
)
Expand All @@ -41,14 +43,16 @@ func Test_templateLogPlugin_Regression(t *testing.T) {
messageFormat core.TaskLog_MessageFormat
}
type args struct {
podName string
podUID string
namespace string
containerName string
containerID string
logName string
podUnixStartTime int64
podUnixFinishTime int64
podName string
podUID string
namespace string
containerName string
containerID string
logName string
podRFC3339StartTime string
podRFC3339FinishTime string
podUnixStartTime int64
podUnixFinishTime int64
}
tests := []struct {
name string
Expand All @@ -64,14 +68,16 @@ func Test_templateLogPlugin_Regression(t *testing.T) {
messageFormat: core.TaskLog_JSON,
},
args{
podName: "f-uuid-driver",
podUID: "pod-uid",
namespace: "flyteexamples-production",
containerName: "spark-kubernetes-driver",
containerID: "cri-o://abc",
logName: "main_logs",
podUnixStartTime: 123,
podUnixFinishTime: 12345,
podName: "f-uuid-driver",
podUID: "pod-uid",
namespace: "flyteexamples-production",
containerName: "spark-kubernetes-driver",
containerID: "cri-o://abc",
logName: "main_logs",
podRFC3339StartTime: "1970-01-01T01:02:03+01:00",
podRFC3339FinishTime: "1970-01-01T04:25:45+01:00",
podUnixStartTime: 123,
podUnixFinishTime: 12345,
},
core.TaskLog{
Uri: "https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logEventViewer:group=/flyte-production/kubernetes;stream=var.log.containers.f-uuid-driver_flyteexamples-production_spark-kubernetes-driver-abc.log",
Expand All @@ -87,14 +93,16 @@ func Test_templateLogPlugin_Regression(t *testing.T) {
messageFormat: core.TaskLog_JSON,
},
args{
podName: "podName",
podUID: "pod-uid",
namespace: "flyteexamples-production",
containerName: "spark-kubernetes-driver",
containerID: "cri-o://abc",
logName: "main_logs",
podUnixStartTime: 123,
podUnixFinishTime: 12345,
podName: "podName",
podUID: "pod-uid",
namespace: "flyteexamples-production",
containerName: "spark-kubernetes-driver",
containerID: "cri-o://abc",
logName: "main_logs",
podRFC3339StartTime: "1970-01-01T01:02:03+01:00",
podRFC3339FinishTime: "1970-01-01T04:25:45+01:00",
podUnixStartTime: 123,
podUnixFinishTime: 12345,
},
core.TaskLog{
Uri: "https://console.cloud.google.com/logs/viewer?project=test-gcp-project&angularJsUrl=%2Flogs%2Fviewer%3Fproject%3Dtest-gcp-project&resource=aws_ec2_instance&advancedFilter=resource.labels.pod_name%3DpodName",
Expand All @@ -110,14 +118,16 @@ func Test_templateLogPlugin_Regression(t *testing.T) {
messageFormat: core.TaskLog_JSON,
},
args{
podName: "flyteexamples-development-task-name",
podUID: "pod-uid",
namespace: "flyteexamples-development",
containerName: "ignore",
containerID: "ignore",
logName: "main_logs",
podUnixStartTime: 123,
podUnixFinishTime: 12345,
podName: "flyteexamples-development-task-name",
podUID: "pod-uid",
namespace: "flyteexamples-development",
containerName: "ignore",
containerID: "ignore",
logName: "main_logs",
podRFC3339StartTime: "1970-01-01T01:02:03+01:00",
podRFC3339FinishTime: "1970-01-01T04:25:45+01:00",
podUnixStartTime: 123,
podUnixFinishTime: 12345,
},
core.TaskLog{
Uri: "https://dashboard.k8s.net/#!/log/flyteexamples-development/flyteexamples-development-task-name/pod?namespace=flyteexamples-development",
Expand All @@ -134,7 +144,7 @@ func Test_templateLogPlugin_Regression(t *testing.T) {
messageFormat: tt.fields.messageFormat,
}

got, err := s.GetTaskLog(tt.args.podName, tt.args.podUID, tt.args.namespace, tt.args.containerName, tt.args.containerID, tt.args.logName, tt.args.podUnixStartTime, tt.args.podUnixFinishTime)
got, err := s.GetTaskLog(tt.args.podName, tt.args.podUID, tt.args.namespace, tt.args.containerName, tt.args.containerID, tt.args.logName, tt.args.podRFC3339FinishTime, tt.args.podRFC3339FinishTime, tt.args.podUnixStartTime, tt.args.podUnixFinishTime)
if (err != nil) != tt.wantErr {
t.Errorf("GetTaskLog() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down Expand Up @@ -170,14 +180,16 @@ func TestTemplateLogPlugin_NewTaskLog(t *testing.T) {
},
args{
input: Input{
HostName: "my-host",
PodName: "my-pod",
Namespace: "my-namespace",
ContainerName: "my-container",
ContainerID: "ignore",
LogName: "main_logs",
PodUnixStartTime: 123,
PodUnixFinishTime: 12345,
HostName: "my-host",
PodName: "my-pod",
Namespace: "my-namespace",
ContainerName: "my-container",
ContainerID: "ignore",
LogName: "main_logs",
PodRFC3339StartTime: "1970-01-01T01:02:03+01:00",
PodRFC3339FinishTime: "1970-01-01T04:25:45+01:00",
PodUnixStartTime: 123,
PodUnixFinishTime: 12345,
},
},
Output{
Expand All @@ -199,14 +211,16 @@ func TestTemplateLogPlugin_NewTaskLog(t *testing.T) {
},
args{
input: Input{
HostName: "my-host",
PodName: "my-pod",
Namespace: "my-namespace",
ContainerName: "my-container",
ContainerID: "ignore",
LogName: "main_logs",
PodUnixStartTime: 123,
PodUnixFinishTime: 12345,
HostName: "my-host",
PodName: "my-pod",
Namespace: "my-namespace",
ContainerName: "my-container",
ContainerID: "ignore",
LogName: "main_logs",
PodRFC3339StartTime: "1970-01-01T01:02:03+01:00",
PodRFC3339FinishTime: "1970-01-01T04:25:45+01:00",
PodUnixStartTime: 123,
PodUnixFinishTime: 12345,
},
},
Output{
Expand All @@ -220,6 +234,37 @@ func TestTemplateLogPlugin_NewTaskLog(t *testing.T) {
},
false,
},
{
"stackdriver-with-rfc3339-timestamp",
fields{
templateURI: "https://console.cloud.google.com/logs/viewer?project=test-gcp-project&angularJsUrl=%2Flogs%2Fviewer%3Fproject%3Dtest-gcp-project&resource=aws_ec2_instance&advancedFilter=resource.labels.pod_name%3D{{.podName}}%20%22{{.podRFC3339StartTime}}%22",
messageFormat: core.TaskLog_JSON,
},
args{
input: Input{
HostName: "my-host",
PodName: "my-pod",
Namespace: "my-namespace",
ContainerName: "my-container",
ContainerID: "ignore",
LogName: "main_logs",
PodRFC3339StartTime: "1970-01-01T01:02:03+01:00",
PodRFC3339FinishTime: "1970-01-01T04:25:45+01:00",
PodUnixStartTime: 123,
PodUnixFinishTime: 12345,
},
},
Output{
TaskLogs: []*core.TaskLog{
{
Uri: "https://console.cloud.google.com/logs/viewer?project=test-gcp-project&angularJsUrl=%2Flogs%2Fviewer%3Fproject%3Dtest-gcp-project&resource=aws_ec2_instance&advancedFilter=resource.labels.pod_name%3Dmy-pod%20%221970-01-01T01:02:03+01:00%22",
MessageFormat: core.TaskLog_JSON,
Name: "main_logs",
},
},
},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 0331ba7

Please sign in to comment.