Get The Job Logs
This API is used to get the training job logs
Path
pkg/apis/arenaclient.TrainingJobClient
Function
func (t *TrainingJobClient) Logs(jobName string, jobType types.TrainingJobType, args *types.LogArgs) error
Parameters
- jobName(type: string) => the name of training job
- jobType(type: pkg/apis/types.TrainingJobType) = > specify the training job type
-
args(type: pkg/apis/types.*LogArgs) => custom the actions of how to get the training job logs,this parameter must generated by pkg/apis/logger.LoggerBuilder,the LoggerBuilder has following functions to custom the LogArgs.
function name description the option matched arena cli SinceSeconds(sinceSeconds string) *LoggerBuilder Only return logs newer than a relative duration like 5s, 2m, or 3h. --since SinceTime(sinceTime string) *LoggerBuilder Only return logs after a specific date (RFC3339) --since-time Instance(name string) *LoggerBuilder specify the instance name -i/--instance Container(name string) *LoggerBuilder specify the container name -c/--container Follow() *LoggerBuilder the logs should be streamed. -f/--fllow Tail(line int) *LoggerBuilder only display the last n lines -t/--tail WriterCloser(writerCloser io.WriteCloser) *LoggerBuilder set the accepter,default is os.Stdout - Build() (*types.LogArgs, error) generate the types.LogArgs -
Example
Only last 10 lines
package main
import(
"fmt"
"github.com/kubeflow/arena/pkg/apis/arenaclient"
"github.com/kubeflow/arena/pkg/apis/types"
)
func main() {
// create the arena client
client, err := arenaclient.NewArenaClient(types.ArenaClientArgs{
Kubeconfig: "",
LogLevel: "debug",
Namespace: "",
ArenaNamespace: "",
IsDaemonMode: false,
})
if err != nil {
fmt.Printf("failed to build arena client.,reason: %v",err)
return
}
// only display the last 10 lines
logArgs, err := logger.NewLoggerBuilder().Tail(10).Build()
if err != nil {
fmt.Printf("failed to build log args,reason: %v\n", err)
return
}
if err := client.Training().Logs("jobName", types.AllTrainingJob, logArgs); err != nil {
fmt.Printf("failed to get job log,reason: %v\n", err)
return
}
}
Real-time display
package main
import(
"fmt"
"github.com/kubeflow/arena/pkg/apis/arenaclient"
"github.com/kubeflow/arena/pkg/apis/types"
)
func main() {
// create the arena client
client, err := arenaclient.NewArenaClient(types.ArenaClientArgs{
Kubeconfig: "",
LogLevel: "debug",
Namespace: "",
ArenaNamespace: "",
IsDaemonMode: false,
})
if err != nil {
fmt.Printf("failed to build arena client.,reason: %v",err)
return
}
// real-time display
logArgs, err := logger.NewLoggerBuilder().Follow().Build()
if err != nil {
fmt.Printf("failed to build log args,reason: %v\n", err)
return
}
if err := client.Training().Logs("jobName", types.AllTrainingJob, logArgs); err != nil {
fmt.Printf("failed to get job log,reason: %v\n", err)
return
}
}
Specify instance name
package main
import(
"fmt"
"github.com/kubeflow/arena/pkg/apis/arenaclient"
"github.com/kubeflow/arena/pkg/apis/types"
)
func main() {
// create the arena client
client, err := arenaclient.NewArenaClient(types.ArenaClientArgs{
Kubeconfig: "",
LogLevel: "debug",
Namespace: "",
ArenaNamespace: "",
IsDaemonMode: false,
})
if err != nil {
fmt.Printf("failed to build arena client.,reason: %v",err)
return
}
// real-time display
logArgs, err := logger.NewLoggerBuilder().Instance("test-instance").Build()
if err != nil {
fmt.Printf("failed to build log args,reason: %v\n", err)
return
}
if err := client.Training().Logs("jobName", types.AllTrainingJob, logArgs); err != nil {
fmt.Printf("failed to get job log,reason: %v\n", err)
return
}
}