Skip to content

Commit 926e8f4

Browse files
authored
feat(log): update log url for job (#1154)
1 parent ad8ebfd commit 926e8f4

File tree

4 files changed

+11
-21
lines changed

4 files changed

+11
-21
lines changed

cmd/server/flag/flags.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,6 @@ func JobFlags(jobConf *config.JobConfig) []cli.Flag {
182182
Usage: "the salt of job log token",
183183
Destination: &jobConf.Log.SaltStr,
184184
},
185-
&cli.StringFlag{
186-
Name: "log-time-format",
187-
Value: jobConf.Log.TimeFormat,
188-
Usage: "the time format of job log token",
189-
Destination: &jobConf.Log.TimeFormat,
190-
},
191185
}
192186
}
193187

pkg/apiserver/controller/job/get.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ var (
4444
}
4545
UpdateTime = time.Now()
4646

47-
defaultSaltStr = "paddleflow"
48-
defaultTimeFormat = "2006-01-02 15"
49-
LogURLFormat = "http://%s:%s/v1/containers/%s/log?jobID=%s&token=%s"
47+
defaultSaltStr = "paddleflow"
48+
LogURLFormat = "http://%s:%s/v1/containers/%s/log?jobID=%s&token=%s&t=%d"
5049
)
5150

5251
func init() {
@@ -408,23 +407,20 @@ func GenerateLogURL(task model.JobTask) string {
408407
containerID = items[1]
409408
}
410409
}
411-
tokenStr := getLogToken(task.JobID, containerID)
410+
tokenStr, t := getLogToken(task.JobID, containerID)
412411
hash := md5.Sum([]byte(tokenStr))
413412
token := hex.EncodeToString(hash[:])
414413
log.Debugf("log url token for task %s/%s is %s", task.JobID, containerID, token)
415414

416415
return fmt.Sprintf(LogURLFormat, config.GlobalServerConfig.Job.Log.ServiceHost,
417-
config.GlobalServerConfig.Job.Log.ServicePort, containerID, task.JobID, token)
416+
config.GlobalServerConfig.Job.Log.ServicePort, containerID, task.JobID, token, t)
418417
}
419418

420-
func getLogToken(jobID, containerID string) string {
419+
func getLogToken(jobID, containerID string) (string, int64) {
421420
saltStr := config.GlobalServerConfig.Job.Log.SaltStr
422421
if saltStr == "" {
423422
saltStr = defaultSaltStr
424423
}
425-
timeFormat := config.GlobalServerConfig.Job.Log.TimeFormat
426-
if timeFormat == "" {
427-
timeFormat = defaultTimeFormat
428-
}
429-
return fmt.Sprintf("%s/%s/%s@%s", jobID, containerID, saltStr, time.Now().Format(timeFormat))
424+
timeStamp := time.Now().Unix()
425+
return fmt.Sprintf("%s/%s/%s@%d", jobID, containerID, saltStr, timeStamp), timeStamp
430426
}

pkg/apiserver/controller/job/get_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestGenerateLogURL(t *testing.T) {
6969
ExtRuntimeStatusJSON: taskStatus,
7070
},
7171
containerID: "8517d2e225a5e580470d56c7e039208b538cb78b942cdabb028e235d1aee54b6",
72-
expectURL: "http://127.0.0.1:8080/v1/containers/%s/log?jobID=test-job-id&token=%s",
72+
expectURL: "http://127.0.0.1:8080/v1/containers/%s/log?jobID=test-job-id&token=%s&t=%d",
7373
},
7474
}
7575

@@ -83,10 +83,11 @@ func TestGenerateLogURL(t *testing.T) {
8383
assert.Equal(t, nil, err)
8484
// generate log url
8585
url := GenerateLogURL(task)
86-
tokenStr := getLogToken(task.JobID, tc.containerID)
86+
tokenStr, timeStamp := getLogToken(task.JobID, tc.containerID)
8787
token := md5.Sum([]byte(tokenStr))
88-
expectURL := fmt.Sprintf(tc.expectURL, tc.containerID, hex.EncodeToString(token[:]))
88+
expectURL := fmt.Sprintf(tc.expectURL, tc.containerID, hex.EncodeToString(token[:]), timeStamp)
8989
assert.Equal(t, expectURL, url)
90+
t.Logf("log url %s", expectURL)
9091
})
9192
}
9293
}

pkg/common/config/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ type JobLogConfig struct {
116116
ServiceHost string `yaml:"serviceHost"`
117117
ServicePort string `yaml:"servicePort"`
118118
SaltStr string `yaml:"saltStr"`
119-
TimeFormat string `yaml:"timeFormat"`
120119
}
121120

122121
type ImageConfig struct {

0 commit comments

Comments
 (0)