Skip to content

Commit

Permalink
Undo changes in generated code and keep helpers private
Browse files Browse the repository at this point in the history
Signed-off-by: Isaac Hier <isaachier@gmail.com>
  • Loading branch information
isaachier committed Dec 5, 2017
1 parent ec5eeff commit d9bd9f4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 45 deletions.
2 changes: 1 addition & 1 deletion examples/hotrod/services/driver/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r *Redis) FindDriverIDs(ctx context.Context, location string) []string {
span.SetTag("param.location", location)
ext.SpanKindRPCClient.Set(span)
defer span.Finish()
_ = opentracing.ContextWithSpan(ctx, span)
ctx = opentracing.ContextWithSpan(ctx, span)
}
// simulate RPC delay
delay.Sleep(config.RedisFindDelay, config.RedisFindDelayStdDev)
Expand Down
17 changes: 0 additions & 17 deletions model/keyvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,6 @@ func (kv *KeyValue) IsLess(two *KeyValue) bool {
}
}

// Matches checks if this KeyValue matches the query key/value pair
func (kv *KeyValue) Matches(key, value string) bool {
return kv.Key == key && kv.AsString() == value
}

func (kvs KeyValues) Len() int { return len(kvs) }
func (kvs KeyValues) Swap(i, j int) { kvs[i], kvs[j] = kvs[j], kvs[i] }
func (kvs KeyValues) Less(i, j int) bool {
Expand Down Expand Up @@ -277,18 +272,6 @@ func (kvs KeyValues) Equal(other KeyValues) bool {
return true
}

// FindMatch checks for a matching KeyValue in the KeyValues for the given
// query key/value pair. Returns the match and true when the match is found.
// Returns empty KeyValue and false when no match is found.
func (kvs KeyValues) FindMatch(key, value string) (KeyValue, bool) {
for _, kv := range kvs {
if kv.Matches(key, value) {
return kv, true
}
}
return KeyValue{}, false
}

// Hash implements Hash from Hashable.
func (kvs KeyValues) Hash(w io.Writer) error {
for i := range kvs {
Expand Down
10 changes: 0 additions & 10 deletions model/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,6 @@ func (s *Span) NormalizeTimestamps() {
}
}

// FlattenTags combines span tags, process tags, and log fields into one KeyValues collection
func (s *Span) FlattenTags() KeyValues {
retMe := s.Tags
retMe = append(retMe, s.Process.Tags...)
for _, l := range s.Logs {
retMe = append(retMe, l.Fields...)
}
return retMe
}

// ------- Flags -------

// SetSampled sets the Flags as sampled
Expand Down
5 changes: 0 additions & 5 deletions pkg/distributedlock/mocks/Lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ import (
"github.com/stretchr/testify/mock"
)

// Lock mocks distributed lock for control of a resource.
type Lock struct {
mock.Mock
}

// Acquire acquires a lease of duration ttl around a given resource. In case of an error,
// acquired is meaningless.
func (_m *Lock) Acquire(resource string, ttl time.Duration) (bool, error) {
ret := _m.Called(resource, ttl)

Expand All @@ -47,8 +44,6 @@ func (_m *Lock) Acquire(resource string, ttl time.Duration) (bool, error) {
return r0, r1
}

// Forfeit forfeits a lease around a given resource. In case of an error,
// forfeited is meaningless.
func (_m *Lock) Forfeit(resource string) (bool, error) {
ret := _m.Called(resource)

Expand Down
10 changes: 0 additions & 10 deletions storage/samplingstore/mocks/Store.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ import "github.com/stretchr/testify/mock"

import "time"

// Store writes and retrieves sampling data to and from storage.
type Store struct {
mock.Mock
}

// InsertThroughput inserts aggregated throughput for operations into storage.
func (_m *Store) InsertThroughput(throughput []*model.Throughput) error {
ret := _m.Called(throughput)

Expand All @@ -37,8 +35,6 @@ func (_m *Store) InsertThroughput(throughput []*model.Throughput) error {

return r0
}

// InsertProbabilitiesAndQPS inserts calculated sampling probabilities and measured qps into storage.
func (_m *Store) InsertProbabilitiesAndQPS(hostname string, probabilities model.ServiceOperationProbabilities, qps model.ServiceOperationQPS) error {
ret := _m.Called(hostname, probabilities, qps)

Expand All @@ -51,8 +47,6 @@ func (_m *Store) InsertProbabilitiesAndQPS(hostname string, probabilities model.

return r0
}

// GetThroughput retrieves aggregated throughput for operations within a time range.
func (_m *Store) GetThroughput(start time.Time, end time.Time) ([]*model.Throughput, error) {
ret := _m.Called(start, end)

Expand All @@ -74,8 +68,6 @@ func (_m *Store) GetThroughput(start time.Time, end time.Time) ([]*model.Through

return r0, r1
}

// GetProbabilitiesAndQPS retrieves the sampling probabilities and measured qps per host within a time range.
func (_m *Store) GetProbabilitiesAndQPS(start time.Time, end time.Time) (map[string][]model.ServiceOperationData, error) {
ret := _m.Called(start, end)

Expand All @@ -97,8 +89,6 @@ func (_m *Store) GetProbabilitiesAndQPS(start time.Time, end time.Time) (map[str

return r0, r1
}

// GetLatestProbabilities retrieves the latest sampling probabilities.
func (_m *Store) GetLatestProbabilities() (model.ServiceOperationProbabilities, error) {
ret := _m.Called()

Expand Down
23 changes: 21 additions & 2 deletions storage/spanstore/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ func (m *Store) validTrace(trace *model.Trace, query *spanstore.TraceQueryParame
return false
}

func findKeyValueMatch(kvs model.KeyValues, key, value string) (model.KeyValue, bool) {
for _, kv := range kvs {
if kv.Key == key && kv.AsString() == value {
return kv, true
}
}
return model.KeyValue{}, false
}

func (m *Store) validSpan(span *model.Span, query *spanstore.TraceQueryParameters) bool {
if query.ServiceName != span.Process.ServiceName {
return false
Expand All @@ -199,11 +208,21 @@ func (m *Store) validSpan(span *model.Span, query *spanstore.TraceQueryParameter
if !query.StartTimeMax.IsZero() && span.StartTime.After(query.StartTimeMax) {
return false
}
spanKVs := span.FlattenTags()
spanKVs := m.flattenTags(span)
for queryK, queryV := range query.Tags {
if _, ok := spanKVs.FindMatch(queryK, queryV); !ok {
// (NB): we cannot find the KeyValues.FindKey function because there can be multiple tags with the same key
if _, ok := findKeyValueMatch(spanKVs, queryK, queryV); !ok {
return false
}
}
return true
}

func (m *Store) flattenTags(span *model.Span) model.KeyValues {
retMe := span.Tags
retMe = append(retMe, span.Process.Tags...)
for _, l := range span.Logs {
retMe = append(retMe, l.Fields...)
}
return retMe
}

0 comments on commit d9bd9f4

Please sign in to comment.