Files
fn-serverless/vendor/google.golang.org/api/examples/mirror.go
Reed Allman 9eaf824398 add jaeger support, link hot container & req span (#840)
* add jaeger support, link hot container & req span

* adds jaeger support now with FN_JAEGER_URL, there's a simple tutorial in the
operating/metrics.md file now and it's pretty easy to get up and running.
* links a hot request span to a hot container span. when we change this to
sample at a lower ratio we'll need to finagle the hot container span to always
sample or something, otherwise we'll hide that info. at least, since we're
sampling at 100% for now if this is flipped on, can see freeze/unfreeze etc.
if they hit. this is useful for debugging. note that zipkin's exporter does
not follow the link at all, hence jaeger... and they're backed by the Cloud
Empire now (CNCF) so we'll probably use it anyway.

* vendor: add thrift for jaeger
2018-03-13 15:57:12 -07:00

98 lines
2.4 KiB
Go

// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"log"
"net/http"
"os"
"strings"
"time"
mirror "google.golang.org/api/mirror/v1"
)
const mirrorLayout = "Jan 2, 2006 at 3:04pm"
func init() {
scopes := []string{
mirror.GlassLocationScope,
mirror.GlassTimelineScope,
}
registerDemo("mirror", strings.Join(scopes, " "), mirrorMain)
}
// mirrorMain is an example that demonstrates calling the Mirror API.
//
// Example usage:
// go build -o go-api-demo *.go
// go-api-demo -clientid="my-clientid" -secret="my-secret" mirror
func mirrorMain(client *http.Client, argv []string) {
if len(argv) != 0 {
fmt.Fprintln(os.Stderr, "Usage: mirror")
return
}
svc, err := mirror.New(client)
if err != nil {
log.Fatalf("Unable to create Mirror service: %v", err)
}
cs, err := svc.Contacts.List().Do()
if err != nil {
log.Fatalf("Unable to retrieve glass contacts: %v", err)
}
if len(cs.Items) == 0 {
log.Printf("You have no glass contacts. Let's add one.")
mom := &mirror.Contact{
DisplayName: "Mom",
Id: "mom",
PhoneNumber: "123-456-7890",
SpeakableName: "mom",
}
_, err := svc.Contacts.Insert(mom).Do()
if err != nil {
log.Fatalf("Unable to add %v to glass contacts: %v", mom.DisplayName, err)
}
}
for _, c := range cs.Items {
log.Printf("Found glass contact %q, phone number: %v", c.DisplayName, c.PhoneNumber)
}
ls, err := svc.Locations.List().Do()
if err != nil {
log.Fatalf("Unable to retrieve glass locations: %v", err)
}
if len(ls.Items) == 0 {
log.Printf("You have no glass locations.")
}
for _, loc := range ls.Items {
t, err := time.Parse(time.RFC3339, loc.Timestamp)
if err != nil {
log.Printf("unable to parse time %q: %v", loc.Timestamp, err)
}
log.Printf("Found glass location: %q at %v, address: %v (lat=%v, lon=%v)", loc.DisplayName, t.Format(mirrorLayout), loc.Address, loc.Latitude, loc.Longitude)
}
ts, err := svc.Timeline.List().Do()
if err != nil {
log.Fatalf("Unable to retrieve glass timeline: %v", err)
}
if len(ts.Items) == 0 {
log.Printf("You have no glass timeline items.")
}
for _, v := range ts.Items {
t, err := time.Parse(time.RFC3339, v.Updated)
if err != nil {
log.Printf("unable to parse time %q: %v", v.Updated, err)
}
log.Printf("Found glass timeline item: %q at %v", v.Text, t.Format(mirrorLayout))
}
}