Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
updates to reuse code from examples/cmd/webapp

rename pkg to webapp so we can import it

manuall install deps

renames influxdb pk name - see: github.com/influxdata/influxdb/issues/5388

updates to correct paths

adds Collect & Trace implementation

cleans up influxdb example

adds Traces implementation & cleanups InfluxDBStore

fixes naming clash

updates to more consistent func names

improvements on Traces implementation

now two queries are executed, one for root spans and other for children spans

use map literals instead for readability

use default point precision 'ms' & set utc time

typo

updates NewInfluxDBStore param signature, using struct instead for consistency.

improves code style

improves strategy for replace existing spans on DB

adds InfluxDBStore.findSpanPoint and removes InfluxDBStore.removeSpanIfExists since not needed anymore

improves root span checking

fields might contain empty values

so better to start annotations slice from zero size

temp fix for frontend hanging

when seeing trace detail page

typo

Revert "temp fix for frontend hanging" - Lasting fix on 7a77805

This reverts commit 38edc7b.

updates to preserve existing span fields

do not replace existing annotations saved on db, just append new ones

use ID's method instead of its implementation

we might want to move zeroID to `id.go`

set all other fields diff than Name too

updates to correct error text

improvements on span annotations updating

handles potential closing errors

if so we should return it

captures potential closing error and logs it

adds trace pagination related todo

updates to handle multiple row values & update docs

due to we already improved the strategy to remove existing span then save new one, now we just append new annotations to the existing span

docs improvements on InfluxDBStore.Collect method

adds missing whitespace

adds support to save `schemas` field to spans measurement

to keep track which schemas were saved by `Collect(...)`

Revert "adds empty time value validation"

This reverts commit 7a77805.

Reverting since not required anymore to prevent ui breaking,
There's a workaround introduced with:
6d10ff7.

adds sorting related improvements

improves comments for `InfluxDBStore`

updates influxdb related paths; fixes introduced on v0.10

therefore not changes on travis related to influxdb import path issues is required - see: influxdata/influxdb#5617

adds support for auth to `InfluxDBStore.server`

typo and fit comments into 80-char-width

updates to keep 80-chars code width limit

Revert "updates to keep 80-chars code width limit"

This reverts commit d589fcb.

adds mode(test, release) support for InfluxDBStore

test mode for running tests & release mode as default.

adds InfluxDBStore tests

tests for Collect & Trace methods

removes httptrace dependency to avoid cyclic dependencies

adds test for InfluxDBStore.Traces()

improvements on comments, unnecessary code & codestyle

adds default retention policy support

which is used to tell appdash database how long time preserve data before deleting it

improves comments readability & adds a low priority TODO

support to add sub-traces to it's trace parent

clean-up TestInfluxDBStore & adds TestFindTraceParent

code readability improvements
  • Loading branch information
chris-ramon committed Mar 6, 2016
1 parent 7a77805 commit 9237015
Show file tree
Hide file tree
Showing 4 changed files with 1,169 additions and 5 deletions.
107 changes: 107 additions & 0 deletions examples/cmd/webapp-influxdb/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package main

import (
"fmt"
"log"
"net/http"
"time"

"sourcegraph.com/sourcegraph/appdash"
"sourcegraph.com/sourcegraph/appdash/httptrace"
"sourcegraph.com/sourcegraph/appdash/traceapp"

"github.com/codegangsta/negroni"
"github.com/gorilla/context"
"github.com/gorilla/mux"

influxDBServer "github.com/influxdata/influxdb/cmd/influxd/run"
"github.com/influxdata/influxdb/toml"
)

const CtxSpanID = 0

var collector appdash.Collector

func main() {
conf, err := influxDBServer.NewDemoConfig()
if err != nil {
log.Fatalf("failed to create influxdb config, error: %v", err)
}

// Enables InfluxDB server authentication.
conf.HTTPD.AuthEnabled = true

// Enables retention policies which will be executed within an interval of 30 minutes.
conf.Retention.Enabled = true
conf.Retention.CheckInterval = toml.Duration(30 * time.Minute)

// InfluxDB server auth credentials. If user does not exist yet it will
// be created as admin user.
user := appdash.InfluxDBAdminUser{Username: "demo", Password: "demo"}

// Retention policy named "one_day_only" with a duration of "1d" - meaning db data older than "1d" will be deleted
// with an interval checking set by `conf.Retention.CheckInterval`.
// Minimum duration time is 1 hour ("1h") - See: github.com/influxdata/influxdb/issues/5198
defaultRP := appdash.InfluxDBRetentionPolicy{Name: "one_day_only", Duration: "1d"}

store, err := appdash.NewInfluxDBStore(appdash.InfluxDBStoreConfig{
AdminUser: user,
BuildInfo: &influxDBServer.BuildInfo{},
DefaultRP: defaultRP,
Server: conf,
})
if err != nil {
log.Fatalf("failed to create influxdb store, error: %v", err)
}
defer func() {
if err := store.Close(); err != nil {
log.Fatal(err)
}
}()
tapp := traceapp.New(nil)
tapp.Store = store
tapp.Queryer = store
log.Println("Appdash web UI running on HTTP :8700")
go func() {
log.Fatal(http.ListenAndServe(":8700", tapp))
}()
collector = appdash.NewLocalCollector(store)
tracemw := httptrace.Middleware(collector, &httptrace.MiddlewareConfig{
RouteName: func(r *http.Request) string { return r.URL.Path },
SetContextSpan: func(r *http.Request, spanID appdash.SpanID) {
context.Set(r, CtxSpanID, spanID)
},
})
router := mux.NewRouter()
router.HandleFunc("/", Home)
router.HandleFunc("/endpoint", Endpoint)
n := negroni.Classic()
n.Use(negroni.HandlerFunc(tracemw))
n.UseHandler(router)
n.Run(":8699")
}

func Home(w http.ResponseWriter, r *http.Request) {
span := context.Get(r, CtxSpanID).(appdash.SpanID)
httpClient := &http.Client{
Transport: &httptrace.Transport{
Recorder: appdash.NewRecorder(span, collector),
SetName: true,
},
}
for i := 0; i < 3; i++ {
resp, err := httpClient.Get("http://localhost:8699/endpoint")
if err != nil {
log.Println("/endpoint:", err)
continue
}
resp.Body.Close()
}
fmt.Fprintf(w, `<p>Three API requests have been made!</p>`)
fmt.Fprintf(w, `<p><a href="http://localhost:8700/traces/%s" target="_">View the trace (ID:%s)</a></p>`, span.Trace, span.Trace)
}

func Endpoint(w http.ResponseWriter, r *http.Request) {
time.Sleep(200 * time.Millisecond)
fmt.Fprintf(w, "Slept for 200ms!")
}
Loading

0 comments on commit 9237015

Please sign in to comment.