本文整理匯總了Golang中github.com/dparrish/openinstrument/variable.ProtoToString函數的典型用法代碼示例。如果您正苦於以下問題:Golang ProtoToString函數的具體用法?Golang ProtoToString怎麽用?Golang ProtoToString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ProtoToString函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestAverage
func (s *MySuite) TestAverage(c *C) {
ctx, cancel := context.WithCancel(context.Background())
e := NewExporter(ctx, s.Client, 10*time.Second)
a := NewAverage(e, variable.NewFromString("/test/average"))
a.Update(95, 1)
a.Update(100, 1)
a.Update(105, 1)
// Force export
streams := e.GetStreams()
c.Assert(len(streams), Equals, 2)
for _, stream := range streams {
switch variable.ProtoToString(stream.Variable) {
case "/test/average-total-count":
c.Check(stream.Value[0].DoubleValue, Equals, 300.0)
case "/test/average-overall-sum":
c.Check(stream.Value[0].DoubleValue, Equals, 3.0)
default:
fmt.Printf("Invalid variable %s", variable.ProtoToString(stream.Variable))
c.Fail()
}
}
cancel()
<-ctx.Done()
}
示例2: TestMean
func (s *MySuite) TestMean(c *C) {
q, err := Parse("mean by (xyz) (/test{host=a}, /test{host=b})")
c.Assert(err, IsNil)
query := q.query
c.Check(variable.ProtoToString(query.Aggregation[0].Query[0].Variable[0]), Equals, "/test{host=a}")
c.Check(variable.ProtoToString(query.Aggregation[0].Query[0].Variable[1]), Equals, "/test{host=b}")
c.Check(query.Aggregation[0].Type, Equals, oproto.StreamAggregation_MEAN)
c.Check(query.Aggregation[0].Label[0], Equals, "xyz")
ch, err := q.Run(context.Background(), s.store)
c.Assert(err, IsNil)
output := []*oproto.ValueStream{}
for stream := range ch {
output = append(output, stream)
}
c.Check(output[0].Value[0].DoubleValue, Equals, float64((20*1+40*1)/2))
c.Check(output[0].Value[1].DoubleValue, Equals, float64((20*2+40*2)/2))
c.Check(output[0].Value[2].DoubleValue, Equals, float64((20*3+40*3)/2))
c.Check(output[0].Value[3].DoubleValue, Equals, float64((20*4+40*4)/2))
c.Check(output[0].Value[4].DoubleValue, Equals, float64((20*5+40*5)/2))
c.Check(output[0].Value[5].DoubleValue, Equals, float64((20*6+40*6)/2))
c.Check(output[0].Value[6].DoubleValue, Equals, float64((20*7+40*7)/2))
c.Check(output[0].Value[7].DoubleValue, Equals, float64((20*8+40*8)/2))
c.Check(output[0].Value[8].DoubleValue, Equals, float64((20*9+40*9)/2))
c.Check(output[0].Value[9].DoubleValue, Equals, float64((20*10+40*10)/2))
c.Check(output[0].Value[10].DoubleValue, Equals, float64((20*11+40*11)/2))
}
示例3: TestRatio
func (s *MySuite) TestRatio(c *C) {
ctx, cancel := context.WithCancel(context.Background())
e := NewExporter(ctx, s.Client, 10*time.Second)
r := NewRatio(e, variable.NewFromString("/test/ratio"))
for i := 0; i < 10; i++ {
r.Success()
}
for i := 0; i < 5; i++ {
r.Failure()
}
// Force export
streams := e.GetStreams()
c.Assert(len(streams), Equals, 3)
for _, stream := range streams {
switch variable.ProtoToString(stream.Variable) {
case "/test/ratio-success":
c.Check(stream.Value[0].DoubleValue, Equals, 10.0)
case "/test/ratio-failure":
c.Check(stream.Value[0].DoubleValue, Equals, 5.0)
case "/test/ratio-total":
c.Check(stream.Value[0].DoubleValue, Equals, 15.0)
default:
fmt.Printf("Invalid variable %s", variable.ProtoToString(stream.Variable))
c.Fail()
}
}
cancel()
<-ctx.Done()
}
示例4: TestTimer
func (s *MySuite) TestTimer(c *C) {
ctx, cancel := context.WithCancel(context.Background())
e := NewExporter(ctx, s.Client, 10*time.Second)
t := NewTimer(e, variable.NewFromString("/test/timer"))
t.Start()
time.Sleep(10 * time.Millisecond)
t.Stop()
t.Start()
time.Sleep(10 * time.Millisecond)
t.Stop()
// Force export
streams := e.GetStreams()
c.Assert(len(streams), Equals, 2)
for _, stream := range streams {
switch variable.ProtoToString(stream.Variable) {
case "/test/timer-total-count":
c.Check((stream.Value[0].DoubleValue >= 20.0 && stream.Value[0].DoubleValue <= 25.0), Equals, true)
case "/test/timer-overall-sum":
c.Check(stream.Value[0].DoubleValue, Equals, 2.0)
default:
fmt.Printf("Invalid variable %s", variable.ProtoToString(stream.Variable))
c.Fail()
}
}
cancel()
<-ctx.Done()
}
示例5: TestAggregationOfMutations
func (s *MySuite) TestAggregationOfMutations(c *C) {
q, err := Parse("mean by (host) (rate(/test{host=a}[1200:1500], /test{host=b}[1200:1500]))")
c.Assert(err, IsNil)
query := q.query
c.Check(query.Aggregation[0].Type, Equals, oproto.StreamAggregation_MEAN)
c.Check(query.Aggregation[0].Query[0].Mutation[0].Type, Equals, oproto.StreamMutation_RATE)
c.Check(variable.ProtoToString(query.Aggregation[0].Query[0].Mutation[0].Query.Variable[0]), Equals, "/test{host=a}[1200:1500]")
c.Check(variable.ProtoToString(query.Aggregation[0].Query[0].Mutation[0].Query.Variable[1]), Equals, "/test{host=b}[1200:1500]")
c.Check(query.Aggregation[0].Query[0].Mutation[0].Query.Variable[0].MinTimestamp, Equals, int64(1200))
c.Check(query.Aggregation[0].Query[0].Mutation[0].Query.Variable[0].MaxTimestamp, Equals, int64(1500))
c.Check(query.Aggregation[0].Query[0].Mutation[0].Query.Variable[1].MinTimestamp, Equals, int64(1200))
c.Check(query.Aggregation[0].Query[0].Mutation[0].Query.Variable[1].MaxTimestamp, Equals, int64(1500))
}
示例6: TestAggregationOfPercentile
func (s *MySuite) TestAggregationOfPercentile(c *C) {
q, err := Parse("percentile(90) by (host) (rate(/test{host=a}[1200:1500], /test{host=b}[1200:1500]))")
c.Assert(err, IsNil)
query := q.query
c.Check(query.Aggregation[0].Type, Equals, oproto.StreamAggregation_PERCENTILE)
c.Check(query.Aggregation[0].Param, Equals, 90.0)
c.Check(query.Aggregation[0].Label[0], Equals, "host")
c.Check(variable.ProtoToString(query.Aggregation[0].Query[0].Mutation[0].Query.Variable[0]), Equals, "/test{host=a}[1200:1500]")
c.Check(variable.ProtoToString(query.Aggregation[0].Query[0].Mutation[0].Query.Variable[1]), Equals, "/test{host=b}[1200:1500]")
c.Check(query.Aggregation[0].Query[0].Mutation[0].Query.Variable[0].MinTimestamp, Equals, int64(1200))
c.Check(query.Aggregation[0].Query[0].Mutation[0].Query.Variable[0].MaxTimestamp, Equals, int64(1500))
c.Check(query.Aggregation[0].Query[0].Mutation[0].Query.Variable[1].MinTimestamp, Equals, int64(1200))
c.Check(query.Aggregation[0].Query[0].Mutation[0].Query.Variable[1].MaxTimestamp, Equals, int64(1500))
}
示例7: AddStream
// AddStream adds a new stream to the unlogged streams list.
// The stream is not flushed to disk until block.Flush() is called (which happens regularly).
func (block *Block) AddStream(stream *oproto.ValueStream) {
block.newStreamsLock.Lock()
defer block.newStreamsLock.Unlock()
v := variable.ProtoToString(stream.Variable)
for _, existingstream := range block.NewStreams {
if variable.ProtoToString(existingstream.Variable) == v {
existingstream.Value = append(existingstream.Value, stream.Value...)
block.Block.UnloggedValues += uint32(len(stream.Value))
return
}
}
block.NewStreams = append(block.NewStreams, stream)
block.Block.UnloggedValues += uint32(len(stream.Value))
block.Block.UnloggedStreams++
}
示例8: TestGetStreamForVariable
func (s *MySuite) TestGetStreamForVariable(c *C) {
block := NewBlock(context.Background(), "/test/foo", "", s.dataDir)
for v := 0; v < 10; v++ {
varName := fmt.Sprintf("/test/bar%d", v)
block.LogStreams[varName] = &oproto.ValueStream{
Variable: &oproto.StreamVariable{Name: varName},
Value: []*oproto.Value{},
}
for i := 0; i < 100; i++ {
block.LogStreams[varName].Value = append(block.LogStreams[varName].Value,
&oproto.Value{DoubleValue: float64(i)})
}
}
c.Assert(block.Compact(context.Background()), IsNil)
found := false
for _, index := range block.Block.Header.Index {
cv := variable.NewFromProto(index.Variable)
if cv.String() != "/test/bar7" {
continue
}
stream := block.getIndexedStream(context.Background(), index)
c.Assert(variable.ProtoToString(stream.Variable), Equals, "/test/bar7")
found = true
break
}
c.Assert(found, Equals, true)
}
示例9: RunLengthEncodeStreams
func (block *Block) RunLengthEncodeStreams(ctx context.Context, streams map[string]*oproto.ValueStream) map[string]*oproto.ValueStream {
// Run-length encode all streams in parallel
var sl sync.Mutex
var outputValues int
wg := &sync.WaitGroup{}
newStreams := make(map[string]*oproto.ValueStream, 0)
for _, stream := range streams {
wg.Add(1)
go func(stream *oproto.ValueStream) {
defer wg.Done()
// Sort values by timestamp
value.By(func(a, b *oproto.Value) bool { return a.Timestamp < b.Timestamp }).Sort(stream.Value)
// Run-length encode values
stream = rle.Encode(stream)
sl.Lock()
newStreams[variable.ProtoToString(stream.Variable)] = stream
outputValues += len(stream.Value)
sl.Unlock()
}(stream)
}
wg.Wait()
openinstrument.Logf(ctx, "Run-length encoded %d streams to %d", len(newStreams), outputValues)
return newStreams
}
示例10: TestMutation
func (s *MySuite) TestMutation(c *C) {
q, err := Parse("rate(/test{host=a})")
c.Assert(err, IsNil)
query := q.query
c.Check(query.Mutation[0].Type, Equals, oproto.StreamMutation_RATE)
c.Check(variable.ProtoToString(query.Mutation[0].Query.Variable[0]), Equals, "/test{host=a}")
ch, err := q.Run(context.Background(), s.store)
c.Assert(err, IsNil)
numStreams := 0
for stream := range ch {
c.Check(variable.ProtoToString(stream.Variable), Equals, "/test{host=a}")
c.Check(len(stream.Value), Equals, 10)
numStreams++
}
c.Check(numStreams, Equals, 1)
}
示例11: TestVariableNoLabels
func (s *MySuite) TestVariableNoLabels(c *C) {
q, err := Parse("/test{}")
c.Assert(err, IsNil)
query := q.query
c.Check(variable.ProtoToString(query.Variable[0]), Equals, "/test")
c.Check(query.Variable[0].MinTimestamp, Equals, int64(0))
c.Check(query.Variable[0].MaxTimestamp, Equals, int64(0))
ch, err := q.Run(context.Background(), s.store)
c.Assert(err, IsNil)
numStreams := 0
for stream := range ch {
c.Check(variable.ProtoToString(stream.Variable), Equals, "/test")
c.Check(len(stream.Value), Equals, 11)
numStreams++
}
c.Check(numStreams, Equals, 1)
}
示例12: TestPercentile
func (s *MySuite) TestPercentile(c *C) {
q, err := Parse("percentile(20) by (host) (/test{host=a})")
c.Assert(err, IsNil)
query := q.query
c.Check(variable.ProtoToString(query.Aggregation[0].Query[0].Variable[0]), Equals, "/test{host=a}")
c.Check(query.Aggregation[0].Type, Equals, oproto.StreamAggregation_PERCENTILE)
c.Check(query.Aggregation[0].Param, Equals, 20.0)
c.Check(query.Aggregation[0].Label[0], Equals, "host")
}
示例13: AddStreams
func (block *Block) AddStreams(c <-chan *oproto.ValueStream) {
block.newStreamsLock.Lock()
defer block.newStreamsLock.Unlock()
CHAN:
for stream := range c {
v := variable.ProtoToString(stream.Variable)
for _, existingstream := range block.NewStreams {
if variable.ProtoToString(existingstream.Variable) == v {
existingstream.Value = append(existingstream.Value, stream.Value...)
block.Block.UnloggedValues += uint32(len(stream.Value))
continue CHAN
}
}
block.NewStreams = append(block.NewStreams, stream)
block.Block.UnloggedValues += uint32(len(stream.Value))
block.Block.UnloggedStreams++
}
}
示例14: TestFloat
func (s *MySuite) TestFloat(c *C) {
ctx, cancel := context.WithCancel(context.Background())
e := NewExporter(ctx, s.Client, 10*time.Second)
f := NewFloat(e, variable.NewFromString("/test/float"))
f.Set(100.0)
// Force export
streams := e.GetStreams()
c.Assert(len(streams), Equals, 1)
c.Check(variable.ProtoToString(streams[0].Variable), Equals, "/test/float")
c.Check(streams[0].Value[0].DoubleValue, Equals, 100.0)
cancel()
<-ctx.Done()
}
示例15: Writer
// Writer builds a channel that can accept ValueStreams for writing to the datastore.
// Any ValueStreams written to this channel will eventually be flushed to disk,
// but they will be immediately available for use.
// The writes to disk are not guaranteed until Flush is called.
func (ds *Datastore) Writer(ctx context.Context) chan<- *oproto.ValueStream {
in := make(chan *oproto.ValueStream, 10)
go func() {
for stream := range in {
// Write this stream
varName := variable.ProtoToString(stream.Variable)
if block := ds.findBlock(ctx, varName); block != nil {
//openinstrument.Logf(ctx, "Writing stream for variable %s to block %s", varName, block.ID())
block.AddStream(stream)
} else {
openinstrument.Logf(ctx, "Unable to find block to write variable %s", varName)
}
}
}()
return in
}