forked from aliyun/aliyun-log-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
etl_meta_example.go
154 lines (144 loc) · 4.63 KB
/
etl_meta_example.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package main
import (
"fmt"
"strings"
sls "github.com/aliyun/aliyun-log-go-sdk"
"github.com/aliyun/aliyun-log-go-sdk/example/util"
)
func main() {
fmt.Println("etl_meta example begin")
sls.GlobalForceUsingHTTP = true
metaKey := "test-meta-key"
createMeta := &sls.EtlMeta{
MetaName: "xx-log",
MetaKey: metaKey,
MetaTag: "123456",
MetaValue: map[string]string{
"aliuid": "123456",
"region": "cn-shenzhen",
"project": "test-project",
"logstore": "test-logstore",
"roleArn": "acs:ram::123456:role/aliyunlogarchiverole",
},
}
err := util.Client.CreateEtlMeta(util.ProjectName, createMeta)
if err != nil {
fmt.Printf("CreateEtlMeta fail, err:%v\n", err)
if strings.Contains(err.Error(), sls.POST_BODY_INVALID) {
return
}
} else {
fmt.Printf("CreateEtlMeta success\n")
}
etlMeta, err := util.Client.GetEtlMeta(util.ProjectName, "xx-log", metaKey)
if err != nil {
fmt.Printf("GetEtlMeta fail, err:%v\n", err)
if strings.Contains(err.Error(), sls.POST_BODY_INVALID) {
return
}
} else {
if etlMeta != nil {
fmt.Printf("GetEtlMeta success, metaName: %s, metaKey: %s, metaTag: %s, metaValue: %s\n",
etlMeta.MetaName, etlMeta.MetaKey, etlMeta.MetaTag, etlMeta.MetaValue)
} else {
fmt.Printf("GetEtlMeta success, no meta hit")
}
}
updateMeta := &sls.EtlMeta{
MetaName: "xx-log",
MetaKey: metaKey,
MetaTag: "123456",
MetaValue: map[string]string{
"aliuid": "123456",
"region": "cn-qingdao",
"project": "test-project-2",
"logstore": "test-logstore-2",
"roleArn": "acs:ram::123456:role/aliyunlogarchiverole",
},
}
err = util.Client.UpdateEtlMeta(util.ProjectName, updateMeta)
if err != nil {
fmt.Printf("UpdateEtlMeta fail, err:%v\n", err)
if strings.Contains(err.Error(), sls.POST_BODY_INVALID) {
return
}
} else {
fmt.Printf("UpdateEtlMeta success\n")
}
etlMeta, err = util.Client.GetEtlMeta(util.ProjectName, "xx-log", metaKey)
if err != nil {
fmt.Printf("GetEtlMeta fail, err:%v\n", err)
if strings.Contains(err.Error(), sls.POST_BODY_INVALID) {
return
}
} else {
if etlMeta != nil {
fmt.Printf("GetEtlMeta success, metaName: %s, metaKey: %s, metaTag: %s, metaValue: %s\n",
etlMeta.MetaName, etlMeta.MetaKey, etlMeta.MetaTag, etlMeta.MetaValue)
} else {
fmt.Printf("GetEtlMeta success, no meta hit")
}
}
err = util.Client.DeleteEtlMeta(util.ProjectName, "xx-log", metaKey)
if err != nil {
fmt.Printf("DeletEtlMeta fail, err:%v\n", err)
if strings.Contains(err.Error(), sls.POST_BODY_INVALID) {
return
}
} else {
fmt.Printf("DeleteEtlMeta success\n")
}
etlMeta, err = util.Client.GetEtlMeta(util.ProjectName, "xx-log", metaKey)
if err != nil {
fmt.Printf("GetEtlMeta fail, err:%v\n", err)
if strings.Contains(err.Error(), sls.POST_BODY_INVALID) {
return
}
} else {
if etlMeta != nil {
fmt.Printf("GetEtlMeta success, metaName: %s, metaKey: %s, metaTag: %s, metaValue: %s\n",
etlMeta.MetaName, etlMeta.MetaKey, etlMeta.MetaTag, etlMeta.MetaValue)
} else {
fmt.Printf("GetEtlMeta success, no meta hit")
}
}
total, count, etlMetaNameList, err := util.Client.ListEtlMetaName(util.ProjectName, 0, 100)
if err != nil {
fmt.Printf("ListEtlMetaName fail, err:%v\n", err)
if strings.Contains(err.Error(), sls.POST_BODY_INVALID) {
return
}
} else if count > 0 {
fmt.Printf("ListEtlMetaName success, total: %d, count: %d\n", total, len(etlMetaNameList))
for index, value := range etlMetaNameList {
fmt.Printf("index: %d, metaName: %s\n", index, value)
}
}
total, count, etlMetaList, err := util.Client.ListEtlMeta(util.ProjectName, "xx-log", 0, 100)
if err != nil {
fmt.Printf("ListEtlMeta fail, err:%v\n", err)
if strings.Contains(err.Error(), sls.POST_BODY_INVALID) {
return
}
} else if count > 0 {
fmt.Printf("ListEtlMeta success, total: %d, count: %d\n", total, len(etlMetaList))
for index, value := range etlMetaList {
fmt.Printf("index: %d, metaName: %s, metaKey: %s, metaTag: %s, metaValue:%s\n",
index, value.MetaName, value.MetaKey, value.MetaTag, value.MetaValue)
}
}
total, count, etlMetaList, err = util.Client.ListEtlMetaWithTag(util.ProjectName, "xx-log", "123456", 0, 100)
if err != nil {
fmt.Printf("ListEtlMetaWithTag fail, err:%v\n", err)
if strings.Contains(err.Error(), sls.POST_BODY_INVALID) {
return
}
} else if count > 0 {
fmt.Printf("ListEtlMetaWithTag success, total: %d, count: %d\n", total, len(etlMetaList))
for index, value := range etlMetaList {
fmt.Printf("index: %d, metaName: %s, metaKey: %s, metaTag: %s, metaValue:%s\n",
index, value.MetaName, value.MetaKey, value.MetaTag, value.MetaValue)
}
}
fmt.Println("etl_meta example end")
}