@@ -22,6 +22,7 @@ type InProcess struct {
22
22
events chan of.Event
23
23
listenerShutdown chan interface {}
24
24
logger * logger.Logger
25
+ serviceMetadata map [string ]interface {}
25
26
sync sync.ISync
26
27
syncEnd context.CancelFunc
27
28
}
@@ -50,6 +51,13 @@ func NewInProcessService(cfg Configuration) *InProcess {
50
51
Selector : cfg .Selector ,
51
52
}, log )
52
53
54
+ // service specific metadata
55
+ var svcMetadata map [string ]interface {}
56
+ if cfg .Selector != "" {
57
+ svcMetadata = make (map [string ]interface {}, 1 )
58
+ svcMetadata ["scope" ] = cfg .Selector
59
+ }
60
+
53
61
flagStore := store .NewFlags ()
54
62
flagStore .FlagSources = append (flagStore .FlagSources , uri )
55
63
@@ -77,6 +85,7 @@ func NewInProcessService(cfg Configuration) *InProcess {
77
85
events : make (chan of.Event , 5 ),
78
86
logger : log ,
79
87
listenerShutdown : make (chan interface {}),
88
+ serviceMetadata : svcMetadata ,
80
89
sync : grpcSync ,
81
90
}
82
91
}
@@ -147,6 +156,7 @@ func (i *InProcess) Shutdown() {
147
156
func (i * InProcess ) ResolveBoolean (ctx context.Context , key string , defaultValue bool ,
148
157
evalCtx map [string ]interface {}) of.BoolResolutionDetail {
149
158
value , variant , reason , metadata , err := i .evaluator .ResolveBooleanValue (ctx , "" , key , evalCtx )
159
+ i .appendMetadata (metadata )
150
160
if err != nil {
151
161
return of.BoolResolutionDetail {
152
162
Value : defaultValue ,
@@ -172,6 +182,7 @@ func (i *InProcess) ResolveBoolean(ctx context.Context, key string, defaultValue
172
182
func (i * InProcess ) ResolveString (ctx context.Context , key string , defaultValue string ,
173
183
evalCtx map [string ]interface {}) of.StringResolutionDetail {
174
184
value , variant , reason , metadata , err := i .evaluator .ResolveStringValue (ctx , "" , key , evalCtx )
185
+ i .appendMetadata (metadata )
175
186
if err != nil {
176
187
return of.StringResolutionDetail {
177
188
Value : defaultValue ,
@@ -197,6 +208,7 @@ func (i *InProcess) ResolveString(ctx context.Context, key string, defaultValue
197
208
func (i * InProcess ) ResolveFloat (ctx context.Context , key string , defaultValue float64 ,
198
209
evalCtx map [string ]interface {}) of.FloatResolutionDetail {
199
210
value , variant , reason , metadata , err := i .evaluator .ResolveFloatValue (ctx , "" , key , evalCtx )
211
+ i .appendMetadata (metadata )
200
212
if err != nil {
201
213
return of.FloatResolutionDetail {
202
214
Value : defaultValue ,
@@ -222,6 +234,7 @@ func (i *InProcess) ResolveFloat(ctx context.Context, key string, defaultValue f
222
234
func (i * InProcess ) ResolveInt (ctx context.Context , key string , defaultValue int64 ,
223
235
evalCtx map [string ]interface {}) of.IntResolutionDetail {
224
236
value , variant , reason , metadata , err := i .evaluator .ResolveIntValue (ctx , "" , key , evalCtx )
237
+ i .appendMetadata (metadata )
225
238
if err != nil {
226
239
return of.IntResolutionDetail {
227
240
Value : defaultValue ,
@@ -247,6 +260,7 @@ func (i *InProcess) ResolveInt(ctx context.Context, key string, defaultValue int
247
260
func (i * InProcess ) ResolveObject (ctx context.Context , key string , defaultValue interface {},
248
261
evalCtx map [string ]interface {}) of.InterfaceResolutionDetail {
249
262
value , variant , reason , metadata , err := i .evaluator .ResolveObjectValue (ctx , "" , key , evalCtx )
263
+ i .appendMetadata (metadata )
250
264
if err != nil {
251
265
return of.InterfaceResolutionDetail {
252
266
Value : defaultValue ,
@@ -273,6 +287,13 @@ func (i *InProcess) EventChannel() <-chan of.Event {
273
287
return i .events
274
288
}
275
289
290
+ func (i * InProcess ) appendMetadata (evalMetadata map [string ]interface {}) {
291
+ // For a nil slice, the number of iterations is 0
292
+ for k , v := range i .serviceMetadata {
293
+ evalMetadata [k ] = v
294
+ }
295
+ }
296
+
276
297
// mapError is a helper to map evaluation errors to OF errors
277
298
func mapError (err error ) of.ResolutionError {
278
299
switch err .Error () {
0 commit comments