当前位置: 首页>>代码示例>>Golang>>正文


Golang variable.Variable类代码示例

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


在下文中一共展示了Variable类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Reader

func (s *FakeReadableStore) Reader(ctx context.Context, v *variable.Variable) <-chan *oproto.ValueStream {
	c := make(chan *oproto.ValueStream, 100)
	go func() {
		defer close(c)
		var stream *oproto.ValueStream
		switch v.Variable {
		case "/test/offset":
			stream = &oproto.ValueStream{
				Variable: v.AsProto(),
				Value: []*oproto.Value{
					{Timestamp: uint64(60 * 0), DoubleValue: float64(20 * 1)},
					{Timestamp: uint64(60 * 1), DoubleValue: float64(20 * 2)},
					{Timestamp: uint64(60 * 2), DoubleValue: float64(20 * 3)},
					{Timestamp: uint64(60 * 3), DoubleValue: float64(20 * 4)},
					{Timestamp: uint64(60 * 4), DoubleValue: float64(20 * 5)},
					{Timestamp: uint64(60 * 5), DoubleValue: float64(20 * 6)},
					{Timestamp: uint64(60 * 6), DoubleValue: float64(20 * 7)},
					{Timestamp: uint64(60 * 7), DoubleValue: float64(20 * 8)},
					{Timestamp: uint64(60 * 8), DoubleValue: float64(20 * 9)},
					{Timestamp: uint64(60 * 9), DoubleValue: float64(20 * 10)},
					{Timestamp: uint64(60 * 10), DoubleValue: float64(20 * 11)},
				},
			}
			if v.Labels["host"] == "a" {
				for _, value := range stream.Value {
					value.Timestamp -= 3
				}
			}
			if v.Labels["host"] == "b" {
				for _, value := range stream.Value {
					value.Timestamp += 5
				}
			}
		case "/test":
			stream = &oproto.ValueStream{
				Variable: v.AsProto(),
				Value: []*oproto.Value{
					{Timestamp: uint64(60 * 0), DoubleValue: float64(20 * 1)},
					{Timestamp: uint64(60 * 1), DoubleValue: float64(20 * 2)},
					{Timestamp: uint64(60 * 2), DoubleValue: float64(20 * 3)},
					{Timestamp: uint64(60 * 3), DoubleValue: float64(20 * 4)},
					{Timestamp: uint64(60 * 4), DoubleValue: float64(20 * 5)},
					{Timestamp: uint64(60 * 5), DoubleValue: float64(20 * 6)},
					{Timestamp: uint64(60 * 6), DoubleValue: float64(20 * 7)},
					{Timestamp: uint64(60 * 7), DoubleValue: float64(20 * 8)},
					{Timestamp: uint64(60 * 8), DoubleValue: float64(20 * 9)},
					{Timestamp: uint64(60 * 9), DoubleValue: float64(20 * 10)},
					{Timestamp: uint64(60 * 10), DoubleValue: float64(20 * 11)},
				},
			}
		}
		if v.Labels["host"] == "b" {
			for _, value := range stream.Value {
				value.DoubleValue *= 2
			}
		}
		c <- stream
	}()
	return c
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:60,代码来源:aggregations_test.go

示例2: NewAverage

func NewAverage(exporter *VariableExporter, v *variable.Variable) *Average {
	sumVar := variable.NewFromProto(v.AsProto())
	sumVar.Variable += "-total-count"
	totalVar := variable.NewFromProto(v.AsProto())
	totalVar.Variable += "-overall-sum"
	return &Average{
		overallSum: NewFloat(exporter, sumVar),
		totalCount: NewInteger(exporter, totalVar),
	}
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:10,代码来源:exported.go

示例3: doesVariableMatch

func doesVariableMatch(itemVar *variable.Variable, policyVars []*oproto.StreamVariable) bool {
	if len(policyVars) == 0 {
		//log.Printf("Stream variable %s matches default policy", itemVar.String())
		return true
	}
	for _, v := range policyVars {
		policyVar := variable.NewFromProto(v)
		if itemVar.Match(policyVar) {
			//log.Printf("Stream variable %s matches policy variable %s", itemVar.String(), policyVar.String())
			return true
		}
		//log.Printf("Stream variable %s doesn't match policy variable %s", itemVar.String(), policyVar.String())
	}
	return false
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:15,代码来源:policy.go

示例4: Reader

// Reader builds a channel that will return streams for a supplied Variable.
// If min/maxTimestamp are not nil, streams will only be returned if SOME values inside the stream match.
// The supplied variable may be a search or a single.
// The streams returned may be out of order with respect to variable names or timestamps.
func (ds *Datastore) Reader(ctx context.Context, v *variable.Variable) <-chan *oproto.ValueStream {
	varName := v.String()
	openinstrument.Logf(ctx, "Creating Reader for %s between %d and %d\n", varName, v.MinTimestamp, v.MaxTimestamp)
	out := make(chan *oproto.ValueStream, 100)
	go func() {
		defer close(out)
		ds.blocksLock.RLock()
		defer ds.blocksLock.RUnlock()
		for _, block := range ds.blocks {
			for stream := range block.Reader(ctx, v) {
				out <- stream
			}
		}
	}()
	return out
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:20,代码来源:datastore.go

示例5: NewRatio

func NewRatio(exporter *VariableExporter, v *variable.Variable) *Ratio {
	successVar := variable.NewFromProto(v.AsProto())
	successVar.Variable += "-success"
	failureVar := variable.NewFromProto(v.AsProto())
	failureVar.Variable += "-failure"
	totalVar := variable.NewFromProto(v.AsProto())
	totalVar.Variable += "-total"
	return &Ratio{
		success: NewInteger(exporter, successVar),
		failure: NewInteger(exporter, failureVar),
		total:   NewInteger(exporter, totalVar),
	}
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:13,代码来源:exported.go

示例6: Reader

func (s *FakeReadableStore) Reader(ctx context.Context, v *variable.Variable) <-chan *oproto.ValueStream {
	c := make(chan *oproto.ValueStream, 100)
	go func() {
		defer close(c)
		switch v.String() {
		case "/test/offset":
			c <- &oproto.ValueStream{
				Variable: v.AsProto(),
				Value: []*oproto.Value{
					{Timestamp: uint64(0), DoubleValue: float64(20)},
					{Timestamp: uint64(61), DoubleValue: float64(40)},
					{Timestamp: uint64(122), DoubleValue: float64(60)},
					{Timestamp: uint64(185), DoubleValue: float64(80)},
					{Timestamp: uint64(241), DoubleValue: float64(100)},
					{Timestamp: uint64(299), DoubleValue: float64(122)},
					{Timestamp: uint64(330), DoubleValue: float64(132)},
					{Timestamp: uint64(359), DoubleValue: float64(140)},
					{Timestamp: uint64(421), DoubleValue: float64(160)},
					{Timestamp: uint64(488), DoubleValue: float64(180)},
					{Timestamp: uint64(540), DoubleValue: float64(200)},
					{Timestamp: uint64(975), DoubleValue: float64(275)},
				},
			}
		default:
			c <- &oproto.ValueStream{
				Variable: v.AsProto(),
				Value: []*oproto.Value{
					{Timestamp: uint64(60 * 0), DoubleValue: float64(20 * 1)},
					{Timestamp: uint64(60 * 1), DoubleValue: float64(20 * 2)},
					{Timestamp: uint64(60 * 2), DoubleValue: float64(20 * 3)},
					{Timestamp: uint64(60 * 3), DoubleValue: float64(20 * 4)},
					{Timestamp: uint64(60 * 4), DoubleValue: float64(20 * 5)},
					{Timestamp: uint64(60 * 5), DoubleValue: float64(20 * 6)},
					{Timestamp: uint64(60 * 6), DoubleValue: float64(20 * 7)},
					{Timestamp: uint64(60 * 7), DoubleValue: float64(20 * 8)},
					{Timestamp: uint64(60 * 8), DoubleValue: float64(20 * 9)},
					{Timestamp: uint64(60 * 9), DoubleValue: float64(20 * 10)},
					{Timestamp: uint64(60 * 10), DoubleValue: float64(20 * 11)},
				},
			}
		}
	}()
	return c
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:44,代码来源:mutations_test.go


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