Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

Adds InfluxDB store. #99

Merged
merged 52 commits into from
Mar 9, 2016
Merged
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7a77805
adds empty time value validation
chris-ramon Feb 3, 2016
ad72e8d
adds initial support for influxdb store
chris-ramon Jan 22, 2016
255c2f3
updates to reuse code from examples/cmd/webapp
chris-ramon Jan 25, 2016
6d805b2
manuall install deps
chris-ramon Jan 22, 2016
4e1dd54
updates to correct paths
chris-ramon Jan 23, 2016
8770314
adds Collect & Trace implementation
chris-ramon Jan 27, 2016
ca50fa5
cleans up influxdb example
chris-ramon Jan 27, 2016
7d6fb1b
adds Traces implementation & cleanups InfluxDBStore
chris-ramon Jan 29, 2016
92361fe
fixes naming clash
chris-ramon Jan 29, 2016
750cbb1
updates to more consistent func names
chris-ramon Jan 29, 2016
56cab8a
improvements on Traces implementation
chris-ramon Jan 29, 2016
9200ceb
use map literals instead for readability
chris-ramon Jan 31, 2016
1fb42e1
use default point precision 'ms' & set utc time
chris-ramon Jan 31, 2016
9b93faa
typo
chris-ramon Feb 1, 2016
58a6762
updates NewInfluxDBStore param signature, using struct instead for co…
chris-ramon Feb 1, 2016
6350b82
improves code style
chris-ramon Feb 1, 2016
ff0908d
improves strategy for replace existing spans on DB
chris-ramon Feb 2, 2016
4f6636d
improves root span checking
chris-ramon Feb 2, 2016
40233de
fields might contain empty values
chris-ramon Feb 2, 2016
38edc7b
temp fix for frontend hanging
chris-ramon Feb 3, 2016
c42412b
typo
chris-ramon Feb 3, 2016
e4435cf
Revert "temp fix for frontend hanging" - Lasting fix on 7a778051de9c5…
chris-ramon Feb 4, 2016
7c8f13f
updates to preserve existing span fields
chris-ramon Feb 4, 2016
f080311
use ID's method instead of its implementation
chris-ramon Feb 8, 2016
5a5b73e
set all other fields diff than Name too
chris-ramon Feb 8, 2016
d79b264
improvements on span annotations updating
chris-ramon Feb 9, 2016
ab57107
handles potential closing errors
chris-ramon Feb 9, 2016
b4a8ae4
captures potential closing error and logs it
chris-ramon Feb 9, 2016
6e47b28
adds trace pagination related todo
chris-ramon Feb 9, 2016
ddebe98
updates to handle multiple row values & update docs
chris-ramon Feb 9, 2016
e23224c
docs improvements on InfluxDBStore.Collect method
chris-ramon Feb 9, 2016
c4a97ba
adds missing whitespace
chris-ramon Feb 9, 2016
6d10ff7
adds support to save `schemas` field to spans measurement
chris-ramon Feb 12, 2016
1ad279d
Revert "adds empty time value validation"
chris-ramon Feb 12, 2016
dc13fa8
adds sorting related improvements
chris-ramon Feb 12, 2016
2f2bc85
improves comments for `InfluxDBStore`
chris-ramon Feb 12, 2016
4123a95
updates influxdb related paths; fixes introduced on v0.10
chris-ramon Feb 13, 2016
f0a959d
adds support for auth to `InfluxDBStore.server`
chris-ramon Feb 15, 2016
d0cf9fb
typo and fit comments into 80-char-width
chris-ramon Feb 16, 2016
d589fcb
updates to keep 80-chars code width limit
chris-ramon Feb 16, 2016
745ea49
Revert "updates to keep 80-chars code width limit"
chris-ramon Feb 16, 2016
77130ee
adds mode(test, release) support for InfluxDBStore
chris-ramon Feb 19, 2016
5db3789
adds InfluxDBStore tests
chris-ramon Feb 19, 2016
49f63e5
removes httptrace dependency to avoid cyclic dependencies
chris-ramon Feb 19, 2016
2d762fe
adds test for InfluxDBStore.Traces()
chris-ramon Feb 19, 2016
f056451
improvements on comments, unnecessary code & codestyle
chris-ramon Feb 23, 2016
4a4b359
adds default retention policy support
chris-ramon Feb 24, 2016
62b5c69
improves comments readability & adds a low priority TODO
chris-ramon Feb 25, 2016
a7fb78f
support to add sub-traces to it's trace parent
chris-ramon Mar 2, 2016
d4354ee
clean-up TestInfluxDBStore & adds TestFindTraceParent
chris-ramon Mar 2, 2016
7024adb
code readability improvements
chris-ramon Mar 2, 2016
ef7a19a
disables reporting to m.influxdb.com
chris-ramon Mar 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "updates to keep 80-chars code width limit"
This reverts commit d589fcb.
  • Loading branch information
chris-ramon committed Feb 16, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 745ea497a0f8ace6359a37417c5c1f15a8ee800c
55 changes: 17 additions & 38 deletions influxdb_store.go
Original file line number Diff line number Diff line change
@@ -15,20 +15,11 @@ import (
)

const (
// InfluxDB db name.
dbName string = "appdash"

// Default number of traces per page.
defaultTracesPerPage int = 10

// Span's measurement field name for schemas field.
schemasFieldName string = "schemas"

// Span's measurement character separator for schemas field.
schemasFieldSeparator string = ","

// InfluxDB container name for trace spans.
spanMeasurementName string = "spans"
dbName string = "appdash" // InfluxDB db name.
defaultTracesPerPage int = 10 // Default number of traces per page.
schemasFieldName string = "schemas" // Span's measurement field name for schemas field.
schemasFieldSeparator string = "," // Span's measurement character separator for schemas field.
spanMeasurementName string = "spans" // InfluxDB container name for trace spans.
)

// Compile-time "implements" check.
@@ -40,8 +31,6 @@ var _ interface {
// zeroID is ID's zero value as string.
var zeroID string = ID(0).String()

var errAdminUserRequired = errors.New("admin user required")

// pointFields -> influxDBClient.Point.Fields
type pointFields map[string]interface{}

@@ -53,8 +42,8 @@ type InfluxDBStore struct {
}

func (in *InfluxDBStore) Collect(id SpanID, anns ...Annotation) error {
// Find a span's point, if found it will be rewritten with new
// annotations(`anns`) if not found, a new span's point will be created.
// Find a span's point, if found it will be rewritten with new annotations(`anns`)
// if not found, a new span's point will be created.
p, err := in.findSpanPoint(id)
if err != nil {
return err
@@ -85,8 +74,7 @@ func (in *InfluxDBStore) Collect(id SpanID, anns ...Annotation) error {
// - Fields that are not saved on DB.
// - Fields that are saved but have empty values.
fields := extendFields(fields, withoutEmptyFields(p.Fields))
schemas, err := mergeSchemasField(schemasFromAnnotations(anns),
p.Fields[schemasFieldName])
schemas, err := mergeSchemasField(schemasFromAnnotations(anns), p.Fields[schemasFieldName])
if err != nil {
return err
}
@@ -126,8 +114,7 @@ func (in *InfluxDBStore) Trace(id ID) (*Trace, error) {
trace := &Trace{}

// GROUP BY * -> meaning group by all tags(trace_id, span_id & parent_id)
// grouping by all tags includes those and it's values on the query
// response.
// grouping by all tags includes those and it's values on the query response.
q := fmt.Sprintf("SELECT * FROM spans WHERE trace_id='%s' GROUP BY *", id)
result, err := in.executeOneQuery(q)
if err != nil {
@@ -172,10 +159,8 @@ func (in *InfluxDBStore) Traces() ([]*Trace, error) {
traces := make([]*Trace, 0)

// GROUP BY * -> meaning group by all tags(trace_id, span_id & parent_id)
// grouping by all tags includes those and it's values on the query
// response.
q := "SELECT * FROM spans WHERE parent_id='%s' GROUP BY * LIMIT %d"
rootSpansQuery := fmt.Sprintf(q, zeroID, in.tracesPerPage)
// grouping by all tags includes those and it's values on the query response.
rootSpansQuery := fmt.Sprintf("SELECT * FROM spans WHERE parent_id='%s' GROUP BY * LIMIT %d", zeroID, in.tracesPerPage)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine for now (limiting to just in.tracesPerPage) but long-term we'll need a way to provide an offset. i.e. to fetch the second page of results. I wonder if InfluxDB can do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we can use offset to provide pagination.

rootSpansResult, err := in.executeOneQuery(rootSpansQuery)
if err != nil {
return nil, err
@@ -212,8 +197,7 @@ func (in *InfluxDBStore) Traces() ([]*Trace, error) {
where := `WHERE `
var i int = 1
for _, trace := range tracesCache {
where += fmt.Sprintf("(trace_id='%s' AND parent_id!='%s')",
trace.Span.ID.Trace, zeroID)
where += fmt.Sprintf("(trace_id='%s' AND parent_id!='%s')", trace.Span.ID.Trace, zeroID)

// Adds 'OR' except for last iteration.
if i != len(tracesCache) && len(tracesCache) > 1 {
@@ -223,8 +207,7 @@ func (in *InfluxDBStore) Traces() ([]*Trace, error) {
}

// Queries for all children spans of the traces to be returned.
childrenSpansQuery := fmt.Sprintf("SELECT * FROM spans %s GROUP BY *",
where)
childrenSpansQuery := fmt.Sprintf("SELECT * FROM spans %s GROUP BY *", where)
childrenSpansResult, err := in.executeOneQuery(childrenSpansQuery)
if err != nil {
return nil, err
@@ -260,8 +243,7 @@ func (in *InfluxDBStore) Close() error {
}

func (in *InfluxDBStore) createDBIfNotExists() error {
// If no errors query execution was successfully - either DB was created or
// already exists.
// If no errors query execution was successfully - either DB was created or already exists.
response, err := in.con.Query(influxDBClient.Query{
Command: fmt.Sprintf("%s %s", "CREATE DATABASE IF NOT EXISTS", dbName),
})
@@ -277,20 +259,17 @@ func (in *InfluxDBStore) createDBIfNotExists() error {
// createAdminUserIfNotExists creates an admin user
// using `in.adminUser` credentials if does not exist.
func (in *InfluxDBStore) createAdminUserIfNotExists() error {
userInfo, err := in.server.MetaClient.Authenticate(in.adminUser.Username,
in.adminUser.Password)
userInfo, err := in.server.MetaClient.Authenticate(in.adminUser.Username, in.adminUser.Password)
if err == influxDBErrors.ErrUserNotFound {
_, createUserErr := in.server.MetaClient.CreateUser(
in.adminUser.Username, in.adminUser.Password, true)
if createUserErr != nil {
if _, createUserErr := in.server.MetaClient.CreateUser(in.adminUser.Username, in.adminUser.Password, true); createUserErr != nil {
return createUserErr
}
return nil
} else {
return err
}
if !userInfo.Admin {
return errAdminUserRequired
return errors.New("failed to validate InfluxDB user type, found non-admin user")
}
return nil
}