本文整理汇总了Golang中github.com/dparrish/openinstrument/variable.NewFromString函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFromString函数的具体用法?Golang NewFromString怎么用?Golang NewFromString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFromString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestMerge
func (s *MySuite) TestMerge(c *C) {
input := []*oproto.ValueStream{
&oproto.ValueStream{
Variable: variable.NewFromString("/test{host=a}").AsProto(),
Value: []*oproto.Value{
&oproto.Value{Timestamp: 1, DoubleValue: 1.0},
&oproto.Value{Timestamp: 4, DoubleValue: 4.0},
},
},
&oproto.ValueStream{
Variable: variable.NewFromString("/test{host=b}").AsProto(),
Value: []*oproto.Value{
&oproto.Value{Timestamp: 2, DoubleValue: 2.0},
&oproto.Value{Timestamp: 5, DoubleValue: 5.0},
},
},
&oproto.ValueStream{
Variable: variable.NewFromString("/test{host=c}").AsProto(),
Value: []*oproto.Value{
&oproto.Value{Timestamp: 3, DoubleValue: 3.0},
&oproto.Value{Timestamp: 6, DoubleValue: 6.0},
},
},
}
outCount, err := checkValueOrder(Merge(input))
if err != nil {
c.Error(err)
}
c.Check(outCount, Equals, 6)
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:30,代码来源:valuestream_test.go
示例2: TestMeanByTwoLabels
func (s *MySuite) TestMeanByTwoLabels(c *C) {
input := []*oproto.ValueStream{
<-s.store.Reader(context.Background(), variable.NewFromString("/test{host=a,job=foo,other=w}")),
<-s.store.Reader(context.Background(), variable.NewFromString("/test{host=a,job=bar,other=x}")),
<-s.store.Reader(context.Background(), variable.NewFromString("/test{host=b,job=foo,other=y}")),
<-s.store.Reader(context.Background(), variable.NewFromString("/test{host=b,job=bar,other=z}")),
}
output := aggregations.Mean([]string{"host", "job"}, input)
c.Assert(output, Not(IsNil))
c.Assert(len(output), Equals, 4)
// Check that there are 4 output streams with the correct number of output labels
checkHostsAndJobs(c, output, 2, 2, 2, 2)
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:13,代码来源:aggregations_test.go
示例3: ListVariables
func ListVariables(ctx context.Context, ds *datastore.Datastore, w http.ResponseWriter, req *http.Request) {
prefix := req.FormValue("p")
if prefix == "" {
prefix = "/*"
}
if prefix[len(prefix)-1] != '*' {
prefix = prefix + "*"
}
v := variable.NewFromString(prefix)
vars := make(map[string]*oproto.StreamVariable)
for stream := range ds.Reader(ctx, v) {
vars[stream.Variable.Name] = stream.Variable
}
if len(vars) == 0 {
w.WriteHeader(404)
return
}
w.WriteHeader(200)
keys := make([]string, len(vars))
i := 0
for k := range vars {
keys[i] = k
i++
}
sort.Strings(keys)
out, _ := json.Marshal(keys)
w.Header().Set("Content-Type", "text/json")
w.Write(out)
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:29,代码来源:http_server.go
示例4: 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
示例5: TestDefaultDropPolicy
func (s *MySuite) TestDefaultDropPolicy(c *C) {
policyTxt := `
interval: 3600
policy {
comment: "Throw everything away"
policy: DROP
}
`
policyProto := &oproto.RetentionPolicy{}
c.Assert(proto.UnmarshalText(policyTxt, policyProto), IsNil)
policy := New(policyProto)
input := &oproto.ValueStream{
Variable: variable.NewFromString("/test/foo/bar").AsProto(),
Value: []*oproto.Value{},
}
for i := 0; i < 10; i++ {
input.Value = append(input.Value, &oproto.Value{Timestamp: uint64(i), DoubleValue: 1.1})
}
output := policy.Apply(input)
for _, value := range output.Value {
log.Printf("Got output when none was expected: %s", value)
c.Fail()
}
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:26,代码来源:policy_test.go
示例6: 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
示例7: 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
示例8: main
func main() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
flag.Parse()
conn, err := grpc.Dial(*connectAddress, grpc.WithInsecure())
if err != nil {
log.Fatalf("Error connecting to %s: %s", *connectAddress, err)
}
defer conn.Close()
request := &oproto.LookupBlockRequest{}
if *varName != "" {
request.Variable = variable.NewFromString(*varName).AsProto()
} else if *ID != "" {
request.BlockId = *ID
} else if len(os.Args) > 1 {
request.BlockId = os.Args[1]
} else {
log.Fatal("Specify either --variable or --id")
}
stub := oproto.NewStoreClient(conn)
response, err := stub.LookupBlock(context.Background(), request)
if err != nil {
log.Fatal(err)
}
log.Println(openinstrument.ProtoText(response))
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:29,代码来源:lookup_block.go
示例9: TestMergeBy
func (s *MySuite) TestMergeBy(c *C) {
input := []*oproto.ValueStream{
&oproto.ValueStream{
Variable: variable.NewFromString("/test{host=a,other=x}").AsProto(),
Value: []*oproto.Value{
&oproto.Value{Timestamp: 1, DoubleValue: 1.0},
&oproto.Value{Timestamp: 4, DoubleValue: 4.0},
},
},
&oproto.ValueStream{
Variable: variable.NewFromString("/test{host=b,other=y}").AsProto(),
Value: []*oproto.Value{
&oproto.Value{Timestamp: 2, DoubleValue: 2.0},
&oproto.Value{Timestamp: 5, DoubleValue: 5.0},
},
},
&oproto.ValueStream{
Variable: variable.NewFromString("/test{host=a,other=z}").AsProto(),
Value: []*oproto.Value{
&oproto.Value{Timestamp: 3, DoubleValue: 3.0},
&oproto.Value{Timestamp: 6, DoubleValue: 6.0},
},
},
}
numSets := 0
for streams := range MergeBy(input, "host") {
stv := variable.NewFromProto(streams[0].Variable)
if stv.Match(variable.NewFromString("/test{host=a}")) {
c.Assert(len(streams), Equals, 2)
outCount, err := checkValueOrder(Merge(streams))
if err != nil {
c.Error(err)
}
c.Check(outCount, Equals, 4)
} else {
c.Check(len(streams), Equals, 1)
outCount, err := checkValueOrder(Merge(streams))
if err != nil {
c.Error(err)
}
c.Check(outCount, Equals, 2)
}
numSets++
}
c.Check(numSets, Equals, 2)
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:46,代码来源:valuestream_test.go
示例10: TestSignedRate
func (s *MySuite) TestSignedRate(c *C) {
for input := range s.store.Reader(context.Background(), variable.NewFromString("/test")) {
output := mutations.SignedRate(input)
for _, v := range output.Value {
checkValue(c, v, v.Timestamp, float64(1)/float64(3))
}
}
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:8,代码来源:mutations_test.go
示例11: TestInterpolate
func (s *MySuite) TestInterpolate(c *C) {
for input := range s.store.Reader(context.Background(), variable.NewFromString("/test/offset")) {
output := mutations.Interpolate(300, input)
checkValue(c, output.Value[0], 0, float64(20))
checkValue(c, output.Value[1], 300, float64(121.81818181818181))
checkValue(c, output.Value[2], 600, float64(191.86046511627907))
checkValue(c, output.Value[3], 900, float64(258.37209302325584))
}
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:9,代码来源:mutations_test.go
示例12: TestMeanBy
func (s *MySuite) TestMeanBy(c *C) {
input := []*oproto.ValueStream{
<-s.store.Reader(context.Background(), variable.NewFromString("/test{host=a,job=foo,other=w}")),
<-s.store.Reader(context.Background(), variable.NewFromString("/test{host=a,job=bar,other=x}")),
<-s.store.Reader(context.Background(), variable.NewFromString("/test{host=b,job=foo,other=y}")),
<-s.store.Reader(context.Background(), variable.NewFromString("/test{host=b,job=bar,other=z}")),
}
output := aggregations.Mean([]string{"host"}, input)
c.Assert(output, Not(IsNil))
c.Assert(len(output), Equals, 2)
// Check that there are two output streams, as there are two distinct hosts
checkHostsAndJobs(c, output, 1, 1, 0, 0)
for _, stream := range output {
c.Assert(len(stream.Value), Equals, 11)
if stream.Variable.Label["host"] == "a" {
checkValue(c, stream.Value[0], 60*0, float64((20*1+20*1)/2))
checkValue(c, stream.Value[1], 60*1, float64((20*2+20*2)/2))
checkValue(c, stream.Value[2], 60*2, float64((20*3+20*3)/2))
checkValue(c, stream.Value[3], 60*3, float64((20*4+20*4)/2))
checkValue(c, stream.Value[4], 60*4, float64((20*5+20*5)/2))
checkValue(c, stream.Value[5], 60*5, float64((20*6+20*6)/2))
checkValue(c, stream.Value[6], 60*6, float64((20*7+20*7)/2))
checkValue(c, stream.Value[7], 60*7, float64((20*8+20*8)/2))
checkValue(c, stream.Value[8], 60*8, float64((20*9+20*9)/2))
checkValue(c, stream.Value[9], 60*9, float64((20*10+20*10)/2))
checkValue(c, stream.Value[10], 60*10, float64((20*11+20*11)/2))
} else if stream.Variable.Label["host"] == "b" {
checkValue(c, stream.Value[0], 60*0, float64((40*1+40*1)/2))
checkValue(c, stream.Value[1], 60*1, float64((40*2+40*2)/2))
checkValue(c, stream.Value[2], 60*2, float64((40*3+40*3)/2))
checkValue(c, stream.Value[3], 60*3, float64((40*4+40*4)/2))
checkValue(c, stream.Value[4], 60*4, float64((40*5+40*5)/2))
checkValue(c, stream.Value[5], 60*5, float64((40*6+40*6)/2))
checkValue(c, stream.Value[6], 60*6, float64((40*7+40*7)/2))
checkValue(c, stream.Value[7], 60*7, float64((40*8+40*8)/2))
checkValue(c, stream.Value[8], 60*8, float64((40*9+40*9)/2))
checkValue(c, stream.Value[9], 60*9, float64((40*10+40*10)/2))
checkValue(c, stream.Value[10], 60*10, float64((40*11+40*11)/2))
} else {
c.Fail()
}
}
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:44,代码来源:aggregations_test.go
示例13: TestMin
func (s *MySuite) TestMin(c *C) {
for input := range s.store.Reader(context.Background(), variable.NewFromString("/test")) {
output := mutations.Min(120, input)
checkValue(c, output.Value[0], 0, 20*1)
checkValue(c, output.Value[1], 120, 20*3)
checkValue(c, output.Value[2], 240, 20*5)
checkValue(c, output.Value[3], 360, 20*7)
checkValue(c, output.Value[4], 480, 20*9)
}
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:10,代码来源:mutations_test.go
示例14: TestMax
func (s *MySuite) TestMax(c *C) {
for input := range s.store.Reader(context.Background(), variable.NewFromString("/test")) {
output := mutations.Max(120, input)
checkValue(c, output.Value[0], 60*2, 20*3)
checkValue(c, output.Value[1], 60*4, 20*5)
checkValue(c, output.Value[2], 60*6, 20*7)
checkValue(c, output.Value[3], 60*8, 20*9)
checkValue(c, output.Value[4], 60*10, 20*11)
}
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:10,代码来源:mutations_test.go
示例15: TestMeanByJob
func (s *MySuite) TestMeanByJob(c *C) {
input := []*oproto.ValueStream{
<-s.store.Reader(context.Background(), variable.NewFromString("/test{host=a,job=foo,other=w}")),
<-s.store.Reader(context.Background(), variable.NewFromString("/test{host=a,job=bar,other=x}")),
<-s.store.Reader(context.Background(), variable.NewFromString("/test{host=b,job=foo,other=y}")),
<-s.store.Reader(context.Background(), variable.NewFromString("/test{host=b,job=bar,other=z}")),
}
output := aggregations.Mean([]string{"job"}, input)
c.Assert(output, Not(IsNil))
c.Assert(len(output), Equals, 2)
// Check that there are two output streams, as there are two distinct hosts
checkHostsAndJobs(c, output, 0, 0, 1, 1)
// First stream is job=foo
stream := output[0]
c.Assert(len(stream.Value), Equals, 11)
checkValue(c, stream.Value[0], 60*0, float64((20*1+40*1)/2))
checkValue(c, stream.Value[1], 60*1, float64((20*2+40*2)/2))
checkValue(c, stream.Value[2], 60*2, float64((20*3+40*3)/2))
checkValue(c, stream.Value[3], 60*3, float64((20*4+40*4)/2))
checkValue(c, stream.Value[4], 60*4, float64((20*5+40*5)/2))
checkValue(c, stream.Value[5], 60*5, float64((20*6+40*6)/2))
checkValue(c, stream.Value[6], 60*6, float64((20*7+40*7)/2))
checkValue(c, stream.Value[7], 60*7, float64((20*8+40*8)/2))
checkValue(c, stream.Value[8], 60*8, float64((20*9+40*9)/2))
checkValue(c, stream.Value[9], 60*9, float64((20*10+40*10)/2))
checkValue(c, stream.Value[10], 60*10, float64((20*11+40*11)/2))
// Second stream is job=bar
stream = output[1]
c.Assert(len(stream.Value), Equals, 11)
checkValue(c, stream.Value[0], 60*0, float64((20*1+40*1)/2))
checkValue(c, stream.Value[1], 60*1, float64((20*2+40*2)/2))
checkValue(c, stream.Value[2], 60*2, float64((20*3+40*3)/2))
checkValue(c, stream.Value[3], 60*3, float64((20*4+40*4)/2))
checkValue(c, stream.Value[4], 60*4, float64((20*5+40*5)/2))
checkValue(c, stream.Value[5], 60*5, float64((20*6+40*6)/2))
checkValue(c, stream.Value[6], 60*6, float64((20*7+40*7)/2))
checkValue(c, stream.Value[7], 60*7, float64((20*8+40*8)/2))
checkValue(c, stream.Value[8], 60*8, float64((20*9+40*9)/2))
checkValue(c, stream.Value[9], 60*9, float64((20*10+40*10)/2))
checkValue(c, stream.Value[10], 60*10, float64((20*11+40*11)/2))
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:43,代码来源:aggregations_test.go
示例16: TestFirst
func (s *MySuite) TestFirst(c *C) {
for input := range s.store.Reader(context.Background(), variable.NewFromString("/test")) {
output := mutations.First(120, input)
c.Assert(len(output.Value), Equals, 6)
checkValue(c, output.Value[0], 60*0, 20*1)
checkValue(c, output.Value[1], 60*2, 20*3)
checkValue(c, output.Value[2], 60*4, 20*5)
checkValue(c, output.Value[3], 60*6, 20*7)
checkValue(c, output.Value[4], 60*8, 20*9)
checkValue(c, output.Value[5], 60*10, 20*11)
}
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:12,代码来源:mutations_test.go
示例17: runAddLoadtest
func runAddLoadtest(ctx context.Context, conn client.Client) {
log.Println("Running ADD load test")
in, out, err := conn.Add(ctx)
if err != nil {
log.Printf("Error starting Add RPC: %s", err)
return
}
defer close(in)
sem := make(semaphore, 1000)
var sent, received int
go func() {
tick := time.Tick(1 * time.Second)
for {
select {
case <-out:
received++
sem.V(1)
case <-tick:
log.Printf("Sent %d, received %d in the last second, latency %0.02fms", sent, received, 1.0/float64(received)*1000.0)
received = 0
sent = 0
}
}
}()
for {
select {
case <-ctx.Done():
return
default:
}
sem.P(1)
v := variable.NewFromString("/test/var1{host=rage}").AsProto()
request := &oproto.AddRequest{
Stream: []*oproto.ValueStream{
{
Variable: v,
Value: []*oproto.Value{
{
Timestamp: openinstrument.NowMs(),
DoubleValue: 1.0,
},
},
},
},
}
in <- request
sent++
}
log.Println("Complete")
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:53,代码来源:cluster.go
示例18: MergeBy
func MergeBy(streams []*oproto.ValueStream, by string) <-chan []*oproto.ValueStream {
c := make(chan []*oproto.ValueStream)
go func() {
uniqueVars := make(map[string]bool)
uniqueLabels := make(map[string]bool)
for _, stream := range streams {
v := variable.NewFromProto(stream.Variable)
uniqueVars[v.Variable] = true
labelValue, ok := v.Labels[by]
if !ok {
uniqueLabels[""] = true
} else {
uniqueLabels[labelValue] = true
}
}
for varname := range uniqueVars {
v := variable.NewFromString(varname)
if by == "" {
var output []*oproto.ValueStream
for _, stream := range streams {
testvar := variable.NewFromProto(stream.Variable)
if testvar.Variable != v.Variable {
continue
}
output = append(output, stream)
}
if len(output) > 0 {
c <- output
}
} else {
for labelvalue := range uniqueLabels {
var output []*oproto.ValueStream
for _, stream := range streams {
testvar := variable.NewFromProto(stream.Variable)
if testvar.Variable != v.Variable {
continue
}
value, ok := testvar.Labels[by]
if ok && value == labelvalue {
output = append(output, stream)
}
}
if len(output) > 0 {
c <- output
}
}
}
}
close(c)
}()
return c
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:52,代码来源:valuestream.go
示例19: runSlowAddLoadtest
func runSlowAddLoadtest(ctx context.Context) {
log.Println("Running ADD load test")
var sent, received int
go func() {
tick := time.Tick(1 * time.Second)
for {
select {
case <-tick:
log.Printf("Sent %d, received %d in the last second, latency %0.02fms", sent, received, 1.0/float64(received)*1000.0)
received = 0
sent = 0
}
}
}()
for {
conn, err := client.NewRpcClient(ctx, *connectAddress)
if err != nil {
log.Fatalf("Error connecting to %s: %s", *connectAddress, err)
}
in, out, err := conn.Add(ctx)
if err != nil {
log.Printf("Error starting Add RPC: %s", err)
return
}
v := variable.NewFromString("/test/var1{host=rage}").AsProto()
request := &oproto.AddRequest{
Stream: []*oproto.ValueStream{
{
Variable: v,
Value: []*oproto.Value{
{
Timestamp: openinstrument.NowMs(),
DoubleValue: 1.0,
},
},
},
},
}
in <- request
close(in)
sent++
<-out
received++
conn.Close()
}
log.Println("Complete")
}
开发者ID:dparrish,项目名称:openinstrument,代码行数:52,代码来源:cluster.go
示例20: 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
注:本文中的github.com/dparrish/openinstrument/variable.NewFromString函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论