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
}
Exemple #2
0
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),
	}
}
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
}
Exemple #4
0
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),
	}
}