Skip to content

Commit d39b6d3

Browse files
committed
Feature: Support Logview V2
1 parent d8d76eb commit d39b6d3

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

odps/logview.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import (
2929
)
3030

3131
const (
32-
HostDefault = "https://logview.alibaba-inc.com"
32+
HostDefault = "https://logview.alibaba-inc.com"
33+
HostDefaultV2 = "https://maxcompute.console.aliyun.com"
3334
)
3435

3536
type LogView struct {
@@ -100,6 +101,17 @@ func (lv *LogView) GenerateLogView(instance *Instance, hours int) (string, error
100101
return logViewUrl.String(), nil
101102
}
102103

104+
func (lv *LogView) GenerateLogViewV2(instance *Instance, regionID string) (string, error) {
105+
client := lv.odpsIns.RestClient()
106+
return fmt.Sprintf("%s/%s/job-insights?h=%s&p=%s&i=%s",
107+
HostDefaultV2,
108+
regionID,
109+
client.Endpoint(),
110+
instance.ProjectName(),
111+
instance.Id(),
112+
), nil
113+
}
114+
103115
func (lv *LogView) generateInstanceToken(instance *Instance, hours int) (string, error) {
104116
policyTpl := `{
105117
"expires_in_hours": %d,

odps/logview_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package odps
2+
3+
import (
4+
"testing"
5+
6+
account2 "github.com/aliyun/aliyun-odps-go-sdk/odps/account"
7+
"github.com/aliyun/aliyun-odps-go-sdk/odps/restclient"
8+
)
9+
10+
var (
11+
account = account2.AccountFromEnv()
12+
endpoint = restclient.LoadEndpointFromEnv()
13+
odpsIns = NewOdps(account, endpoint)
14+
defaultProjectName = "go_sdk_regression_testing"
15+
)
16+
17+
func TestLogView_GenerateLogViewV2(t *testing.T) {
18+
odpsIns.SetDefaultProjectName(defaultProjectName)
19+
instance := NewInstance(odpsIns, defaultProjectName, "20221027160000000001000001")
20+
logView := NewLogView(odpsIns)
21+
url, err := logView.GenerateLogViewV2(instance, "cn-shanghai")
22+
if err != nil {
23+
t.Error(err)
24+
}
25+
println(url)
26+
expect := "https://maxcompute.console.aliyun.com/cn-shanghai/job-insights?h=http://service.cn-shanghai.maxcompute.aliyun.com/api&p=go_sdk_regression_testing&i=20221027160000000001000001"
27+
if url != expect {
28+
t.Errorf("expect %s, but got %s", expect, url)
29+
}
30+
}

0 commit comments

Comments
 (0)