LogShipper操作
更新时间:2024-09-12
创建LogShipper
创建投递任务,需要遵循以下准则:
- 每个日志集可以创建多个投递任务
- 总投递任务上限为300
- 投递任务名称,最长63个字符,包含字母、数字、-和_
- 投递开始时间,最早为前180天,最迟为后24小时,默认为任务创建时间为开始时间,格式为ISO8601
createLogShipperRequest := CreateLogShipperRequest{
LogShipperName: "test",
Project: "default",
LogStoreName: "test",
StartTime: time.Now().UTC().Format("2006-01-02T15:04:05Z"),
DestType: "BOS",
DestConfig: &api.ShipperDestConfig{
BOSPath: "bls-test/sdk-log-shipper-test/",
PartitionFormatTS: "%Y/%m/%d/%H/%M/",
PartitionFormatLogStream: false,
MaxObjectSize: 64,
CompressType: "none",
DeliverInterval: 5,
StorageFormat: "json",
ShipperType: "text",
},
}
id, err := BLS_CLIENT.CreateLogShipperV2(createLogShipperRequest)
if err != nil {
fmt.Println("Create LogShipper failed: ", err)
} else {
fmt.Printf("Create LogShipper %s success.", id)
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档CreateLogShipper
更新指定LogShipper
通过以下代码,更新指定的投递任务,目前不支持更改投递任务的日志集、起始时间和目的类型
updateLogShipperRequest := UpdateLogShipperRequest{
LogShipperID: "vxkAJtxc5hGbJIu2JwkqI5Ux",
LogShipperName: "test",
DestConfig: &api.ShipperDestConfig{
BOSPath: "bls-test/sdk-log-shipper-test/",
PartitionFormatTS: "%Y/%m/%d/%H/%M/",
PartitionFormatLogStream: false,
MaxObjectSize: 128,
CompressType: "none",
DeliverInterval: 10,
StorageFormat: "JSON",
},
}
err := BLS_CLIENT.UpdateLogShipperV2(updateLogShipperRequest)
if err != nil {
fmt.Println("Update LogShipper failed: ", err)
} else {
fmt.Println("Update LogShipper success.")
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档UpdateLogShipper
查询指定LogShipper
通过以下代码,获取指定投递任务的详情信息。
getLogShipperRequest := GetLogShipperRequest{
LogShipperID: "vxkAJtxc5hGbJIu2JwkqI5Ux",
}
res, err := BLS_CLIENT.GetLogShipperV2(getLogShipperRequest)
if err != nil {
fmt.Println("Get LogShipper failed: ", err)
} else {
fmt.Println("LogShipper info: ", res)
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档GetLogShipper
获取LogShipper列表
通过以下代码,查看符合查询条件的投递任务。
listLogShipperRequest := ListLogShipperRequest{
Project: "default",
LogStoreName: "test",
PageNo: 1,
PageSize: 10,
}
res, err := BLS_CLIENT.ListLogShipperV2(listLogShipperRequest)
if err != nil {
fmt.Println("Get LogShipper list failed: ", err)
} else {
fmt.Println("List LogShipper success: ", res)
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档ListLogShipper
查看LogShipper执行记录
通过以下代码,查看投递任务的执行记录。
listShipperRecordRequest := ListShipperRecordRequest{
LogShipperID: "vxkAJtxc5hGbJIu2JwkqI5Ux",
}
res, err := BLS_CLIENT.ListLogShipperRecordV2(listShipperRecordRequest)
if err != nil {
fmt.Println("Get LogShipper record failed: ", err)
} else {
fmt.Println("Get LogShipper record success: ", res)
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档ListLogShipperRecord
启停LogShipper
单个启停
通过以下代码,启停指定的投递任务。
updateLogShipperStatusRequest := UpdateLogShipperStatusRequest{
LogShipperID: "vxkAJtxc5hGbJIu2JwkqI5Ux",
DesiredStatus: "Paused",
}
err := BLS_CLIENT.UpdateLogShipperStatusV2(updateLogShipperStatusRequest)
if err != nil {
fmt.Println("Set LogShipper status failed: ", err)
} else {
fmt.Println("Set LogShipper status success.")
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档SetSingleLogShipperStatus
批量启停
通过以下代码,批量启停投递任务。
bulkUpdateLogShipperStatusRequest := BulkUpdateLogShipperStatusRequest{
LogShipperIDs: []string{"vxkAJtxc5hGbJIu2JwkqI5Ux"},
DesiredStatus: "Paused",
}
err := BLS_CLIENT.BulkUpdateLogShipperStatusV2(bulkUpdateLogShipperStatusRequest)
if err != nil {
fmt.Println("Bulk set LogShipper status failed: ", err)
} else {
fmt.Println("Bulk set LogShipper status success.")
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档BulkSetLogShipperStatus
删除LogShipper
单个删除
通过以下代码,删除指定的投递任务。
deleteLogShipperRequest := DeleteLogShipperRequest{
LogShipperID: "vxkAJtxc5hGbJIu2JwkqI5Ux",
}
err := BLS_CLIENT.DeleteLogShipperV2(deleteLogShipperRequest)
if err != nil {
fmt.Println("Delete LogShipper failed: ", err)
} else {
fmt.Println("Delete LogShipper success.")
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档DeleteSingleLogShipper
批量删除
通过以下代码,批量删除投递任务。
bulkDeleteLogShipperRequest := BulkDeleteLogShipperRequest{
LogShipperIDs: []string{"vxkAJtxc5hGbJIu2JwkqI5Ux"},
}
err := BLS_CLIENT.BulkDeleteLogShipperV2(bulkDeleteLogShipperRequest)
if err != nil {
fmt.Println("Bulk delete LogShipper failed: ", err)
} else {
fmt.Println("Bulk delete LogShipper success.")
}
提示:
- 详细的参数配置及限制条件,可以参考BLS API 文档BulkDeleteLogShipper