Skip to content

Instantly share code, notes, and snippets.

@aLekSer
Created June 10, 2020 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aLekSer/daaaeb270351300c1ba1e82adf23dcee to your computer and use it in GitHub Desktop.
Save aLekSer/daaaeb270351300c1ba1e82adf23dcee to your computer and use it in GitHub Desktop.
Simple example of the mako stub usage
package main
import (
"context"
"flag"
"fmt"
"time"
"github.com/gogo/protobuf/proto"
"github.com/google/mako/go/quickstore"
qpb "github.com/google/mako/proto/quickstore/quickstore_go_proto"
"knative.dev/pkg/signals"
)
func main() {
// parse the command line flags
flag.Parse()
// We want this for properly handling Kubernetes container lifecycle events.
ctx := signals.NewContext()
// We cron every 5 minutes, so make sure that we don't severely overrun to
// limit how noisy a neighbor we can be.
ctx, cancel := context.WithTimeout(ctx, 6*time.Minute)
defer cancel()
// Use the benchmark key created
microservice := fmt.Sprintf("localhost:%d", 9813)
// Use a fresh context here so that our RPC to terminate the sidecar
// isn't subject to our timeout (or we won't shut it down when we time out)
sendTime := time.Now()
elapsed := time.Now().Sub(sendTime)
benchmarkKey := "5251279936815104"
input := &qpb.QuickstoreInput{
BenchmarkKey: proto.String(benchmarkKey),
}
fmt.Printf("Connecting to microservice at %s...\n", microservice)
q, closeq, err := quickstore.NewAtAddress(ctx, input, microservice)
if err != nil {
fmt.Println(err, "is an error")
}
defer closeq(ctx)
m := map[string]float64{}
m["sdf"] = float64(elapsed)
q.AddSamplePoint(float64(20000), m)
_, err = q.Store()
if err != nil {
fmt.Printf("quickstore Store() = %s", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment