Skip to content

Commit aa85686

Browse files
committed
sn/policer: Add component log field at the application level
Except SN app, the Policer is used only for tests where this field is unnecessary. Signed-off-by: Leonard Lyubich <[email protected]>
1 parent 2f681ae commit aa85686

File tree

3 files changed

+21
-39
lines changed

3 files changed

+21
-39
lines changed

cmd/neofs-node/object.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func initObjectService(c *cfg) {
194194
)
195195

196196
c.shared.policer = policer.New(
197-
policer.WithLogger(c.log),
197+
policer.WithLogger(c.log.With(zap.String("component", "Object Policer"))),
198198
policer.WithLocalStorage(ls),
199199
policer.WithRemoteHeader(
200200
headsvc.NewRemoteHeader(keyStorage, clientConstructor),

pkg/services/policer/policer.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ func New(opts ...Option) *Policer {
140140
opts[i](c)
141141
}
142142

143-
c.log = c.log.With(zap.String("component", "Object Policer"))
144-
145143
return &Policer{
146144
cfg: c,
147145
objsInWork: &objectsInWork{

pkg/services/policer/policer_test.go

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ func TestPolicer_Run_RepDefault(t *testing.T) {
4747
res := testRepCheck(t, defaultRep, nodes, i, true, allOK, 0, true, nil)
4848
res.logBuf.AssertContains(testutil.LogEntry{
4949
Level: zap.InfoLevel, Message: "local replica of the object is redundant in the container, removing...", Fields: map[string]any{
50-
"component": "Object Policer",
51-
"object": oid.NewAddress(res.cnr, res.obj).String(),
50+
"object": oid.NewAddress(res.cnr, res.obj).String(),
5251
},
5352
})
5453
}
@@ -59,17 +58,15 @@ func TestPolicer_Run_RepDefault(t *testing.T) {
5958
res := testRepCheck(t, defaultRep, nodes, -1, true, allOK, 0, true, nil)
6059
res.logBuf.AssertContains(testutil.LogEntry{
6160
Level: zap.InfoLevel, Message: "node outside the container, removing the replica so as not to violate the storage policy...", Fields: map[string]any{
62-
"component": "Object Policer",
63-
"object": oid.NewAddress(res.cnr, res.obj).String(),
61+
"object": oid.NewAddress(res.cnr, res.obj).String(),
6462
},
6563
})
6664
})
6765
t.Run("out netmap", func(t *testing.T) {
6866
res := testRepCheck(t, defaultRep, nodes, -1, false, allOK, 0, false, nil)
6967
res.logBuf.AssertContains(testutil.LogEntry{
7068
Level: zap.InfoLevel, Message: "node is outside the network map, holding the replica...", Fields: map[string]any{
71-
"component": "Object Policer",
72-
"object": oid.NewAddress(res.cnr, res.obj).String(),
69+
"object": oid.NewAddress(res.cnr, res.obj).String(),
7370
},
7471
})
7572
})
@@ -95,8 +92,7 @@ func TestPolicer_Run_RepDefault(t *testing.T) {
9592
res := testRepCheck(t, defaultRep, nodes, -1, true, allNotFound, defaultRep, false, nodes)
9693
res.logBuf.AssertContains(testutil.LogEntry{
9794
Level: zap.InfoLevel, Message: "node outside the container, but nobody stores the object, holding the replica...", Fields: map[string]any{
98-
"component": "Object Policer",
99-
"object": oid.NewAddress(res.cnr, res.obj).String(),
95+
"object": oid.NewAddress(res.cnr, res.obj).String(),
10096
},
10197
})
10298
})
@@ -117,8 +113,7 @@ func TestPolicer_Run_RepDefault(t *testing.T) {
117113
res := testRepCheck(t, defaultRep, nodes, i, true, errs, 0, false, nil)
118114
res.logBuf.AssertContains(testutil.LogEntry{
119115
Level: zap.DebugLevel, Message: "some of the copies are stored on nodes under maintenance, save local copy", Fields: map[string]any{
120-
"component": "Object Policer",
121-
"count": json.Number("2"),
116+
"count": json.Number("2"),
122117
},
123118
})
124119
for j := range defaultRep {
@@ -127,8 +122,7 @@ func TestPolicer_Run_RepDefault(t *testing.T) {
127122
}
128123
res.logBuf.AssertContains(testutil.LogEntry{
129124
Level: zap.DebugLevel, Message: "consider node under maintenance as OK", Fields: map[string]any{
130-
"component": "Object Policer",
131-
"node": hex.EncodeToString(nodes[j].PublicKey()),
125+
"node": hex.EncodeToString(nodes[j].PublicKey()),
132126
},
133127
})
134128
}
@@ -139,15 +133,13 @@ func TestPolicer_Run_RepDefault(t *testing.T) {
139133
res := testRepCheck(t, defaultRep, nodes, i, true, errs, 0, false, nil)
140134
res.logBuf.AssertContains(testutil.LogEntry{
141135
Level: zap.DebugLevel, Message: "some of the copies are stored on nodes under maintenance, save local copy", Fields: map[string]any{
142-
"component": "Object Policer",
143-
"count": json.Number("3"),
136+
"count": json.Number("3"),
144137
},
145138
})
146139
for j := range defaultRep {
147140
res.logBuf.AssertContains(testutil.LogEntry{
148141
Level: zap.DebugLevel, Message: "consider node under maintenance as OK", Fields: map[string]any{
149-
"component": "Object Policer",
150-
"node": hex.EncodeToString(nodes[j].PublicKey()),
142+
"node": hex.EncodeToString(nodes[j].PublicKey()),
151143
},
152144
})
153145
}
@@ -159,15 +151,13 @@ func TestPolicer_Run_RepDefault(t *testing.T) {
159151
res := testRepCheck(t, defaultRep, nodes, -1, true, errs, 0, false, nil)
160152
res.logBuf.AssertContains(testutil.LogEntry{
161153
Level: zap.DebugLevel, Message: "some of the copies are stored on nodes under maintenance, save local copy", Fields: map[string]any{
162-
"component": "Object Policer",
163-
"count": json.Number("3"),
154+
"count": json.Number("3"),
164155
},
165156
})
166157
for j := range defaultRep {
167158
res.logBuf.AssertContains(testutil.LogEntry{
168159
Level: zap.DebugLevel, Message: "consider node under maintenance as OK", Fields: map[string]any{
169-
"component": "Object Policer",
170-
"node": hex.EncodeToString(nodes[j].PublicKey()),
160+
"node": hex.EncodeToString(nodes[j].PublicKey()),
171161
},
172162
})
173163
}
@@ -176,15 +166,13 @@ func TestPolicer_Run_RepDefault(t *testing.T) {
176166
res := testRepCheck(t, defaultRep, nodes, -1, false, errs, 0, false, nil)
177167
res.logBuf.AssertContains(testutil.LogEntry{
178168
Level: zap.DebugLevel, Message: "some of the copies are stored on nodes under maintenance, save local copy", Fields: map[string]any{
179-
"component": "Object Policer",
180-
"count": json.Number("3"),
169+
"count": json.Number("3"),
181170
},
182171
})
183172
for j := range defaultRep {
184173
res.logBuf.AssertContains(testutil.LogEntry{
185174
Level: zap.DebugLevel, Message: "consider node under maintenance as OK", Fields: map[string]any{
186-
"component": "Object Policer",
187-
"node": hex.EncodeToString(nodes[j].PublicKey()),
175+
"node": hex.EncodeToString(nodes[j].PublicKey()),
188176
},
189177
})
190178
}
@@ -204,9 +192,8 @@ func TestPolicer_Run_RepDefault(t *testing.T) {
204192
Level: zap.ErrorLevel,
205193
Message: "receive object header to check policy compliance",
206194
Fields: map[string]any{
207-
"component": "Object Policer",
208-
"object": oid.NewAddress(res.cnr, res.obj).String(),
209-
"error": "non-status error",
195+
"object": oid.NewAddress(res.cnr, res.obj).String(),
196+
"error": "non-status error",
210197
},
211198
}
212199
res.logBuf.AssertContains(e)
@@ -230,9 +217,8 @@ func TestPolicer_Run_RepDefault(t *testing.T) {
230217
Level: zap.ErrorLevel,
231218
Message: "receive object header to check policy compliance",
232219
Fields: map[string]any{
233-
"component": "Object Policer",
234-
"object": oid.NewAddress(res.cnr, res.obj).String(),
235-
"error": "non-status error",
220+
"object": oid.NewAddress(res.cnr, res.obj).String(),
221+
"error": "non-status error",
236222
},
237223
}
238224
res.logBuf.AssertContains(e)
@@ -261,9 +247,8 @@ func TestPolicer_Run_RepDefault(t *testing.T) {
261247
Level: zap.ErrorLevel,
262248
Message: "receive object header to check policy compliance",
263249
Fields: map[string]any{
264-
"component": "Object Policer",
265-
"object": oid.NewAddress(res.cnr, res.obj).String(),
266-
"error": "non-status error",
250+
"object": oid.NewAddress(res.cnr, res.obj).String(),
251+
"error": "non-status error",
267252
},
268253
}
269254
res.logBuf.AssertContains(e)
@@ -287,9 +272,8 @@ func TestPolicer_Run_RepDefault(t *testing.T) {
287272
Level: zap.ErrorLevel,
288273
Message: "receive object header to check policy compliance",
289274
Fields: map[string]any{
290-
"component": "Object Policer",
291-
"object": oid.NewAddress(res.cnr, res.obj).String(),
292-
"error": "non-status error",
275+
"object": oid.NewAddress(res.cnr, res.obj).String(),
276+
"error": "non-status error",
293277
},
294278
}
295279
res.logBuf.AssertContains(e)

0 commit comments

Comments
 (0)