88 "errors"
99 "fmt"
1010 "io"
11- "strconv"
1211 "time"
1312
1413 "google.golang.org/grpc"
@@ -278,26 +277,12 @@ func readTrace(stream storage_v1.SpanReaderPlugin_GetTraceClient) (*model.Trace,
278277
279278func (c * GRPCClient ) InsertThroughput (throughputs []* samplingStoreModel.Throughput ) error {
280279 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
298283 }
299284
300- _ , err : = c .samplingStoreClient .InsertThroughput (ctx , & storage_v1.InsertThroughputRequest {
285+ _ , err = c .samplingStoreClient .InsertThroughput (ctx , & storage_v1.InsertThroughputRequest {
301286 Throughput : storageV1Throughput ,
302287 })
303288 if err != nil {
@@ -309,27 +294,14 @@ func (c *GRPCClient) InsertThroughput(throughputs []*samplingStoreModel.Throughp
309294
310295func (c * GRPCClient ) InsertProbabilitiesAndQPS (hostname string , probabilities samplingStoreModel.ServiceOperationProbabilities , qps samplingStoreModel.ServiceOperationQPS ) error {
311296 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- }
325297
326298 _ , err := c .samplingStoreClient .InsertProbabilitiesAndQPS (ctx , & storage_v1.InsertProbabilitiesAndQPSRequest {
327299 Hostname : hostname ,
328300 Probabilities : & storage_v1.ServiceOperationProbabilities {
329- ServiceOperationProbabilities : convertToV1Map (probabilities ),
301+ ServiceOperationProbabilities : sSFloatMapToStorageV1SSFloatMap (probabilities ),
330302 },
331303 Qps : & storage_v1.ServiceOperationQPS {
332- ServiceOperationQPS : convertToV1Map (qps ),
304+ ServiceOperationQPS : sSFloatMapToStorageV1SSFloatMap (qps ),
333305 },
334306 })
335307 if err != nil {
@@ -349,23 +321,7 @@ func (c *GRPCClient) GetThroughput(start, end time.Time) ([]*samplingStoreModel.
349321 return nil , fmt .Errorf ("plugin error: %w" , err )
350322 }
351323
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
369325}
370326
371327func (c * GRPCClient ) GetLatestProbabilities () (samplingStoreModel.ServiceOperationProbabilities , error ) {
@@ -375,17 +331,5 @@ func (c *GRPCClient) GetLatestProbabilities() (samplingStoreModel.ServiceOperati
375331 return nil , fmt .Errorf ("plugin error: %w" , err )
376332 }
377333
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
391335}
0 commit comments