• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang variable.ProtoToString函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/dparrish/openinstrument/variable.ProtoToString函数的典型用法代码示例。如果您正苦于以下问题:Golang ProtoToString函数的具体用法?Golang ProtoToString怎么用?Golang ProtoToString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ProtoToString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:26,代码来源:exported_test.go


示例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))
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:28,代码来源:query_test.go


示例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()
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:32,代码来源:exported_test.go


示例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()
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:30,代码来源:exported_test.go


示例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))
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:13,代码来源:query_test.go


示例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))
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:14,代码来源:query_test.go


示例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++
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:17,代码来源:block.go


示例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)
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:27,代码来源:block_test.go


示例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
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:27,代码来源:block.go


示例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)
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:17,代码来源:query_test.go


示例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)
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:18,代码来源:query_test.go


示例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")
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:9,代码来源:query_test.go


示例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++
	}
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:20,代码来源:block.go


示例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()
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:14,代码来源:exported_test.go


示例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
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:20,代码来源:datastore.go


示例16: LookupBlock

func (s *server) LookupBlock(ctx context.Context, request *oproto.LookupBlockRequest) (*oproto.LookupBlockResponse, error) {
	if request.BlockId != "" {
		block, err := s.ds.GetBlock(request.BlockId, "")
		if err != nil {
			return nil, err
		}
		return &oproto.LookupBlockResponse{Block: block.ToProto()}, nil
	}
	v := variable.ProtoToString(request.Variable)
	for _, block := range s.ds.Blocks() {
		if block.EndKey() >= v {
			return &oproto.LookupBlockResponse{Block: block.ToProto()}, nil
		}
	}
	return &oproto.LookupBlockResponse{}, nil
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:16,代码来源:rpc_server.go


示例17: InspectVariable

func InspectVariable(ctx context.Context, ds *datastore.Datastore, w http.ResponseWriter, req *http.Request) {
	t, err := template.ParseFiles(fmt.Sprintf("%s/inspect_variable.html", *templatePath))
	if err != nil {
		openinstrument.Logf(ctx, "Couldn't find template file: %s", err)
		return
	}
	type varInfo struct {
		Name           string
		FirstTimestamp time.Time
		LastTimestamp  time.Time
	}
	p := struct {
		Title     string
		Query     string
		Variables []varInfo
	}{
		Title:     "Inspect Variable",
		Query:     req.FormValue("q"),
		Variables: make([]varInfo, 0),
	}

	if p.Query == "" {
		w.WriteHeader(404)
		fmt.Fprintf(w, "Specify q=")
		return
	}

	v := variable.NewFromString(p.Query)
	c := ds.Reader(ctx, v)
	for stream := range c {
		lt := stream.Value[len(stream.Value)-1].EndTimestamp
		if lt == 0 {
			lt = stream.Value[len(stream.Value)-1].Timestamp
		}
		p.Variables = append(p.Variables, varInfo{
			Name:           variable.ProtoToString(stream.Variable),
			FirstTimestamp: time.Unix(int64(stream.Value[0].Timestamp/1000), 0),
			LastTimestamp:  time.Unix(int64(lt/1000), 0),
		})
	}

	err = t.Execute(w, p)
	if err != nil {
		log.Println(err)
	}
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:46,代码来源:http_server.go


示例18: readBlockLog

func (ds *Datastore) readBlockLog(ctx context.Context, filename string) {
	block := NewBlock(ctx, "", BlockIDFromFilename(filename), ds.Path)

	file, err := protofile.Read(block.logFilename())
	if err != nil {
		openinstrument.Logf(ctx, "Error opening proto log file %s: %s", block.logFilename(), err)
	}
	defer file.Close()

	// Read all the streams from the log file
	reader := file.ValueStreamReader(ctx, 100)
	for stream := range reader {
		varName := variable.ProtoToString(stream.Variable)
		if varName > block.EndKey() {
			block.Block.EndKey = varName
		}
		locker := block.LogWriteLocker()
		locker.Lock()
		existingstream, found := block.LogStreams[varName]
		if found {
			existingstream.Value = append(existingstream.Value, stream.Value...)
		} else {
			block.LogStreams[varName] = stream
		}
		locker.Unlock()
	}

	if func() *Block {
		for _, existingblock := range ds.Blocks() {
			if existingblock.ID() == block.ID() {
				locker := existingblock.LogWriteLocker()
				locker.Lock()
				existingblock.LogStreams = block.LogStreams
				locker.Unlock()
				// Update cached number of streams and values
				existingblock.UpdateLoggedCount()
				return existingblock
			}
		}
		return nil
	}() == nil {
		// There is no existing block file for this log.
		block.UpdateLoggedCount()
		ds.insertBlock(ctx, block)
	}
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:46,代码来源:datastore.go


示例19: Flush

func (block *Block) Flush() error {
	block.newStreamsLock.Lock()
	defer block.newStreamsLock.Unlock()

	if len(block.NewStreams) == 0 {
		return nil
	}

	block.logLock.Lock()
	defer block.logLock.Unlock()

	// There are streams that need to be flushed to disk
	file, err := protofile.Write(block.logFilename())
	if err != nil {
		return err
	}
	defer file.Close()
	for _, stream := range block.NewStreams {
		n, err := file.Write(stream)
		if err != nil || n < 1 {
			return err
		}
		varName := variable.ProtoToString(stream.Variable)
		existingstream, found := block.LogStreams[varName]
		if found {
			existingstream.Value = append(existingstream.Value, stream.Value...)
		} else {
			block.LogStreams[varName] = stream
		}
	}
	block.NewStreams = make([]*oproto.ValueStream, 0)
	block.Block.LoggedStreams += block.Block.UnloggedStreams
	block.Block.LoggedValues += block.Block.UnloggedValues
	block.Block.UnloggedStreams = uint32(0)
	block.Block.UnloggedValues = uint32(0)
	block.UpdateSize()

	return nil
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:39,代码来源:block.go


示例20: List

func (s *server) List(ctx context.Context, request *oproto.ListRequest) (*oproto.ListResponse, error) {
	response := &oproto.ListResponse{
		Timer: make([]*oproto.LogMessage, 0),
	}

	requestVariable := variable.NewFromProto(request.Prefix)
	if len(requestVariable.Variable) == 0 {
		return nil, fmt.Errorf("No variable specified")
	}

	// Retrieve all variables and store the names in a map for uniqueness
	timer := openinstrument.NewTimer(ctx, "retrieve variables")
	vars := make(map[string]*oproto.StreamVariable)
	if requestVariable.MinTimestamp == 0 {
		// Get the last day
		requestVariable.MinTimestamp = -86400000
	}
	for stream := range s.ds.Reader(ctx, requestVariable) {
		if request.MaxVariables == 0 || len(vars) < int(request.MaxVariables) {
			vars[variable.ProtoToString(stream.Variable)] = stream.Variable
		}
	}
	timer.Stop()

	// Build the response out of the map
	timer = openinstrument.NewTimer(ctx, "construct response")
	response.Variable = make([]*oproto.StreamVariable, 0)
	for _, variable := range vars {
		response.Variable = append(response.Variable, variable)
	}
	response.Success = true
	timer.Stop()

	log.Printf("Timers: %s", openinstrument.GetLog(ctx))
	return response, nil
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:36,代码来源:rpc_server.go



注:本文中的github.com/dparrish/openinstrument/variable.ProtoToString函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang variable.Variable类代码示例发布时间:2022-05-23
下一篇:
Golang variable.NewFromString函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap