This repository has been archived by the owner on Mar 16, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 207
/
logging.go
237 lines (218 loc) · 6.32 KB
/
logging.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/**
* @Time : 2019-06-28 10:33
* @Author : solacowa@gmail.com
* @File : logging
* @Software: GoLand
*/
package deployment
import (
"context"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
kithttp "github.com/go-kit/kit/transport/http"
"github.com/kplcloud/kplcloud/src/middleware"
"time"
)
type loggingService struct {
logger log.Logger
Service
}
func NewLoggingService(logger log.Logger, s Service) Service {
return &loggingService{level.Info(logger), s}
}
func (s *loggingService) GetYaml(ctx context.Context) (res interface{}, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "GetYaml",
"took", time.Since(begin),
"name", ctx.Value(middleware.NameContext),
"namespace", ctx.Value(middleware.NamespaceContext),
"err", err,
)
}(time.Now())
return s.Service.GetYaml(ctx)
}
func (s *loggingService) CommandArgs(ctx context.Context, commands []string, args []string) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "CommandArgs",
"took", time.Since(begin),
"name", ctx.Value(middleware.NameContext),
"namespace", ctx.Value(middleware.NamespaceContext),
"err", err,
)
}(time.Now())
return s.Service.CommandArgs(ctx, commands, args)
}
func (s *loggingService) Expansion(ctx context.Context, requestCpu, limitCpu, requestMemory, limitMemory string) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Expansion",
"took", time.Since(begin),
"name", ctx.Value(middleware.NameContext),
"namespace", ctx.Value(middleware.NamespaceContext),
"requestCpu", requestCpu,
"limitCpu", limitCpu,
"requestMemory", requestMemory,
"limitLimit", limitMemory,
"err", err,
)
}(time.Now())
return s.Service.Expansion(ctx, requestCpu, limitCpu, requestMemory, limitMemory)
}
func (s *loggingService) Stretch(ctx context.Context, num int) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Stretch",
"took", time.Since(begin),
"name", ctx.Value(middleware.NameContext),
"namespace", ctx.Value(middleware.NamespaceContext),
"num", num,
"err", err,
)
}(time.Now())
return s.Service.Stretch(ctx, num)
}
func (s *loggingService) GetPvc(ctx context.Context, ns, name string) (res map[string]interface{}, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "GetPvc",
"took", time.Since(begin),
"name", name,
"namespace", ns,
"err", err,
)
}(time.Now())
return s.Service.GetPvc(ctx, ns, name)
}
func (s *loggingService) BindPvc(ctx context.Context, ns, name, path, claimName string) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "BindPvc",
"took", time.Since(begin),
"name", name,
"namespace", ns,
"claimName", claimName,
"path", path,
"err", err,
)
}(time.Now())
return s.Service.BindPvc(ctx, ns, name, path, claimName)
}
func (s *loggingService) UnBindPvc(ctx context.Context, ns, name, claimName string) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "UnBindPvc",
"took", time.Since(begin),
"name", name,
"namespace", ns,
"claimName", claimName,
"err", err,
)
}(time.Now())
return s.Service.UnBindPvc(ctx, ns, name, claimName)
}
func (s *loggingService) AddPort(ctx context.Context, ns, name string, req portRequest) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "AddPort",
"took", time.Since(begin),
"name", name,
"namespace", ns,
"err", err,
)
}(time.Now())
return s.Service.AddPort(ctx, ns, name, req)
}
func (s *loggingService) DelPort(ctx context.Context, ns, name string, portName string, port int32) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "DelPort",
"took", time.Since(begin),
"name", name,
"namespace", ns,
"portNaeme", portName,
"port", port,
"err", err,
)
}(time.Now())
return s.Service.DelPort(ctx, ns, name, portName, port)
}
func (s *loggingService) Logging(ctx context.Context, ns, name, pattern, suffix string, paths []string) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Logging",
"took", time.Since(begin),
"name", name,
"namespace", ns,
"pattern", pattern,
"suffix", suffix,
"err", err,
)
}(time.Now())
return s.Service.Logging(ctx, ns, name, pattern, suffix, paths)
}
func (s *loggingService) Probe(ctx context.Context, ns, name string, req probeRequest) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Probe",
"took", time.Since(begin),
"name", name,
"namespace", ns,
"port", req.Port,
"probe", req.Probe,
"path", req.Path,
"err", err,
)
}(time.Now())
return s.Service.Probe(ctx, ns, name, req)
}
func (s *loggingService) Mesh(ctx context.Context, ns, name, model string) (err error) {
//ctx = context.WithValue(ctx,"OperationMethod", repository.SwitchModel)
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Mesh",
"took", time.Since(begin),
"name", name,
"namespace", ns,
"model", model,
"err", err,
)
}(time.Now())
return s.Service.Mesh(ctx, ns, name, model)
}
func (s *loggingService) Hosts(ctx context.Context, hosts []string) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Hosts",
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.Hosts(ctx, hosts)
}
func (s *loggingService) VolumeConfig(ctx context.Context, mountPath, subPath string) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"method", "VolumeConfig",
"mountPath", mountPath,
"subPath", subPath,
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.VolumeConfig(ctx, mountPath, subPath)
}