8
8
"errors"
9
9
"fmt"
10
10
"io"
11
- "strconv"
12
11
"time"
13
12
14
13
"google.golang.org/grpc"
@@ -278,26 +277,12 @@ func readTrace(stream storage_v1.SpanReaderPlugin_GetTraceClient) (*model.Trace,
278
277
279
278
func (c * GRPCClient ) InsertThroughput (throughputs []* samplingStoreModel.Throughput ) error {
280
279
ctx := context .Background ()
281
- storageV1Throughput := []* storage_v1.Throughput {}
282
- for _ , throughput := range throughputs {
283
- probsAsArray := []float64 {}
284
- for prob := range throughput .Probabilities {
285
- probInFloat , err := strconv .ParseFloat (prob , 64 )
286
- if err != nil {
287
- return err
288
- }
289
- probsAsArray = append (probsAsArray , probInFloat )
290
- }
291
-
292
- storageV1Throughput = append (storageV1Throughput , & storage_v1.Throughput {
293
- Service : throughput .Service ,
294
- Operation : throughput .Operation ,
295
- Count : throughput .Count ,
296
- Probabilities : probsAsArray ,
297
- })
280
+ storageV1Throughput , err := samplingStoreThroughpusToStorageV1Throughputs (throughputs )
281
+ if err != nil {
282
+ return err
298
283
}
299
284
300
- _ , err : = c .samplingStoreClient .InsertThroughput (ctx , & storage_v1.InsertThroughputRequest {
285
+ _ , err = c .samplingStoreClient .InsertThroughput (ctx , & storage_v1.InsertThroughputRequest {
301
286
Throughput : storageV1Throughput ,
302
287
})
303
288
if err != nil {
@@ -309,27 +294,14 @@ func (c *GRPCClient) InsertThroughput(throughputs []*samplingStoreModel.Throughp
309
294
310
295
func (c * GRPCClient ) InsertProbabilitiesAndQPS (hostname string , probabilities samplingStoreModel.ServiceOperationProbabilities , qps samplingStoreModel.ServiceOperationQPS ) error {
311
296
ctx := context .Background ()
312
- stringFloatMapToV1StringFloatMap := func (in map [string ]float64 ) * storage_v1.StringFloatMap {
313
- return & storage_v1.StringFloatMap {
314
- StringFloatMap : in ,
315
- }
316
- }
317
-
318
- convertToV1Map := func (in map [string ]map [string ]float64 ) map [string ]* storage_v1.StringFloatMap {
319
- res := make (map [string ]* storage_v1.StringFloatMap )
320
- for k , v := range in {
321
- res [k ] = stringFloatMapToV1StringFloatMap (v )
322
- }
323
- return res
324
- }
325
297
326
298
_ , err := c .samplingStoreClient .InsertProbabilitiesAndQPS (ctx , & storage_v1.InsertProbabilitiesAndQPSRequest {
327
299
Hostname : hostname ,
328
300
Probabilities : & storage_v1.ServiceOperationProbabilities {
329
- ServiceOperationProbabilities : convertToV1Map (probabilities ),
301
+ ServiceOperationProbabilities : sSFloatMapToStorageV1SSFloatMap (probabilities ),
330
302
},
331
303
Qps : & storage_v1.ServiceOperationQPS {
332
- ServiceOperationQPS : convertToV1Map (qps ),
304
+ ServiceOperationQPS : sSFloatMapToStorageV1SSFloatMap (qps ),
333
305
},
334
306
})
335
307
if err != nil {
@@ -349,23 +321,7 @@ func (c *GRPCClient) GetThroughput(start, end time.Time) ([]*samplingStoreModel.
349
321
return nil , fmt .Errorf ("plugin error: %w" , err )
350
322
}
351
323
352
- resThroughput := []* samplingStoreModel.Throughput {}
353
-
354
- for _ , throughput := range resp .Throughput {
355
- probsAsSet := make (map [string ]struct {})
356
- for _ , prob := range throughput .Probabilities {
357
- probsAsSet [strconv .FormatFloat (prob , 'E' , - 1 , 64 )] = struct {}{}
358
- }
359
-
360
- resThroughput = append (resThroughput , & samplingStoreModel.Throughput {
361
- Service : throughput .Service ,
362
- Operation : throughput .Operation ,
363
- Count : throughput .Count ,
364
- Probabilities : probsAsSet ,
365
- })
366
- }
367
-
368
- return resThroughput , nil
324
+ return storageV1ThroughputsToSamplingStoreThroughputs (resp .Throughput ), nil
369
325
}
370
326
371
327
func (c * GRPCClient ) GetLatestProbabilities () (samplingStoreModel.ServiceOperationProbabilities , error ) {
@@ -375,17 +331,5 @@ func (c *GRPCClient) GetLatestProbabilities() (samplingStoreModel.ServiceOperati
375
331
return nil , fmt .Errorf ("plugin error: %w" , err )
376
332
}
377
333
378
- v1StringFloatMapToStringFloatMap := func (in * storage_v1.StringFloatMap ) map [string ]float64 {
379
- return in .StringFloatMap
380
- }
381
-
382
- convertToMap := func (in map [string ]* storage_v1.StringFloatMap ) map [string ]map [string ]float64 {
383
- res := make (map [string ]map [string ]float64 )
384
- for k , v := range in {
385
- res [k ] = v1StringFloatMapToStringFloatMap (v )
386
- }
387
- return res
388
- }
389
-
390
- return convertToMap (resp .ServiceOperationProbabilities .ServiceOperationProbabilities ), nil
334
+ return storageV1SSFloatMapToSSFloatMap (resp .ServiceOperationProbabilities .ServiceOperationProbabilities ), nil
391
335
}
0 commit comments