From 2605c407d7d219644d03a3680ad7df4779017782 Mon Sep 17 00:00:00 2001 From: Prateek Rungta Date: Sun, 30 Jul 2017 21:52:21 -0400 Subject: [PATCH] Rename sanitise to sanitize (#51) --- m3/{sanitise.go => sanitize.go} | 4 +- sanitise.go => sanitize.go | 70 ++++++++++++++-------------- sanitise_test.go => sanitize_test.go | 12 ++--- scope.go | 50 ++++++++++---------- scope_benchmark_test.go | 4 +- scope_test.go | 14 +++--- 6 files changed, 77 insertions(+), 77 deletions(-) rename m3/{sanitise.go => sanitize.go} (93%) rename sanitise.go => sanitize.go (69%) rename sanitise_test.go => sanitize_test.go (87%) diff --git a/m3/sanitise.go b/m3/sanitize.go similarity index 93% rename from m3/sanitise.go rename to m3/sanitize.go index 4cc7b719..856f6ad1 100644 --- a/m3/sanitise.go +++ b/m3/sanitize.go @@ -25,8 +25,8 @@ import ( ) var ( - // DefaultSanitiserOpts are the options for the default M3 Sanitiser - DefaultSanitiserOpts = tally.SanitiseOptions{ + // DefaultSanitizerOpts are the options for the default M3 Sanitizer + DefaultSanitizerOpts = tally.SanitizeOptions{ NameCharacters: tally.ValidCharacters{ Ranges: tally.AlphanumericRange, Characters: tally.UnderscoreDashDotCharacters, diff --git a/sanitise.go b/sanitize.go similarity index 69% rename from sanitise.go rename to sanitize.go index cdcfba63..592ef480 100644 --- a/sanitise.go +++ b/sanitize.go @@ -30,7 +30,7 @@ var ( DefaultReplacementCharacter = '_' // AlphanumericRange is the range of alphanumeric characters. - AlphanumericRange = []SanitiseRange{ + AlphanumericRange = []SanitizeRange{ {rune('a'), rune('z')}, {rune('A'), rune('Z')}, {rune('0'), rune('9')}} @@ -49,78 +49,78 @@ var ( '_'} ) -// SanitiseFn returns a sanitised version of the input string. -type SanitiseFn func(string) string +// SanitizeFn returns a sanitized version of the input string. +type SanitizeFn func(string) string -// SanitiseRange is a range of characters (inclusive on both ends). -type SanitiseRange [2]rune +// SanitizeRange is a range of characters (inclusive on both ends). +type SanitizeRange [2]rune // ValidCharacters is a collection of valid characters. type ValidCharacters struct { - Ranges []SanitiseRange + Ranges []SanitizeRange Characters []rune } -// SanitiseOptions are the set of configurable options for sanitisation. -type SanitiseOptions struct { +// SanitizeOptions are the set of configurable options for sanitisation. +type SanitizeOptions struct { NameCharacters ValidCharacters KeyCharacters ValidCharacters ValueCharacters ValidCharacters ReplacementCharacter rune } -// Sanitiser sanitises the provided input based on the function executed. -type Sanitiser interface { - // Name sanitises the provided `name` string. +// Sanitizer sanitizes the provided input based on the function executed. +type Sanitizer interface { + // Name sanitizes the provided `name` string. Name(n string) string - // Key sanitises the provided `key` string. + // Key sanitizes the provided `key` string. Key(k string) string - // Value sanitises the provided `value` string. + // Value sanitizes the provided `value` string. Value(v string) string } -// NewSanitiser returns a new sanitiser based on provided options. -func NewSanitiser(opts SanitiseOptions) Sanitiser { - return sanitiser{ - nameFn: opts.NameCharacters.sanitiseFn(opts.ReplacementCharacter), - keyFn: opts.KeyCharacters.sanitiseFn(opts.ReplacementCharacter), - valueFn: opts.ValueCharacters.sanitiseFn(opts.ReplacementCharacter), +// NewSanitizer returns a new sanitizer based on provided options. +func NewSanitizer(opts SanitizeOptions) Sanitizer { + return sanitizer{ + nameFn: opts.NameCharacters.sanitizeFn(opts.ReplacementCharacter), + keyFn: opts.KeyCharacters.sanitizeFn(opts.ReplacementCharacter), + valueFn: opts.ValueCharacters.sanitizeFn(opts.ReplacementCharacter), } } -// NoOpSanitiseFn returns the input un-touched. -func NoOpSanitiseFn(v string) string { return v } +// NoOpSanitizeFn returns the input un-touched. +func NoOpSanitizeFn(v string) string { return v } -// NewNoOpSanitiser returns a sanitiser which returns all inputs un-touched. -func NewNoOpSanitiser() Sanitiser { - return sanitiser{ - nameFn: NoOpSanitiseFn, - keyFn: NoOpSanitiseFn, - valueFn: NoOpSanitiseFn, +// NewNoOpSanitizer returns a sanitizer which returns all inputs un-touched. +func NewNoOpSanitizer() Sanitizer { + return sanitizer{ + nameFn: NoOpSanitizeFn, + keyFn: NoOpSanitizeFn, + valueFn: NoOpSanitizeFn, } } -type sanitiser struct { - nameFn SanitiseFn - keyFn SanitiseFn - valueFn SanitiseFn +type sanitizer struct { + nameFn SanitizeFn + keyFn SanitizeFn + valueFn SanitizeFn } -func (s sanitiser) Name(n string) string { +func (s sanitizer) Name(n string) string { return s.nameFn(n) } -func (s sanitiser) Key(k string) string { +func (s sanitizer) Key(k string) string { return s.keyFn(k) } -func (s sanitiser) Value(v string) string { +func (s sanitizer) Value(v string) string { return s.valueFn(v) } -func (c *ValidCharacters) sanitiseFn(repChar rune) SanitiseFn { +func (c *ValidCharacters) sanitizeFn(repChar rune) SanitizeFn { return func(value string) string { var buf *bytes.Buffer for idx, ch := range value { diff --git a/sanitise_test.go b/sanitize_test.go similarity index 87% rename from sanitise_test.go rename to sanitize_test.go index e4767a25..43c842c8 100644 --- a/sanitise_test.go +++ b/sanitize_test.go @@ -26,22 +26,22 @@ import ( "github.com/stretchr/testify/require" ) -func newTestSanitiser() SanitiseFn { +func newTestSanitizer() SanitizeFn { c := &ValidCharacters{ Ranges: AlphanumericRange, Characters: UnderscoreDashCharacters, } - return c.sanitiseFn(DefaultReplacementCharacter) + return c.sanitizeFn(DefaultReplacementCharacter) } -func TestSanitiseIdentifierAllValidCharacters(t *testing.T) { +func TestSanitizeIdentifierAllValidCharacters(t *testing.T) { allValidChars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_" - fn := newTestSanitiser() + fn := newTestSanitizer() require.Equal(t, allValidChars, fn(allValidChars)) } -func TestSanitiseTestCases(t *testing.T) { - fn := newTestSanitiser() +func TestSanitizeTestCases(t *testing.T) { + fn := newTestSanitizer() type testCase struct { input string output string diff --git a/scope.go b/scope.go index 42e278b7..cbd06027 100644 --- a/scope.go +++ b/scope.go @@ -64,7 +64,7 @@ type scope struct { cachedReporter CachedStatsReporter baseReporter BaseStatsReporter defaultBuckets Buckets - sanitiser Sanitiser + sanitizer Sanitizer registry *scopeRegistry status scopeStatus @@ -101,7 +101,7 @@ type ScopeOptions struct { CachedReporter CachedStatsReporter Separator string DefaultBuckets Buckets - SanitiseOptions *SanitiseOptions + SanitizeOptions *SanitizeOptions } // NewRootScope creates a new root Scope with a set of options and @@ -123,9 +123,9 @@ func NewTestScope( } func newRootScope(opts ScopeOptions, interval time.Duration) *scope { - sanitiser := NewNoOpSanitiser() - if o := opts.SanitiseOptions; o != nil { - sanitiser = NewSanitiser(*o) + sanitizer := NewNoOpSanitizer() + if o := opts.SanitizeOptions; o != nil { + sanitizer = NewSanitizer(*o) } if opts.Tags == nil { @@ -147,13 +147,13 @@ func newRootScope(opts ScopeOptions, interval time.Duration) *scope { } s := &scope{ - separator: sanitiser.Name(opts.Separator), - prefix: sanitiser.Name(opts.Prefix), + separator: sanitizer.Name(opts.Separator), + prefix: sanitizer.Name(opts.Prefix), reporter: opts.Reporter, cachedReporter: opts.CachedReporter, baseReporter: baseReporter, defaultBuckets: opts.DefaultBuckets, - sanitiser: sanitiser, + sanitizer: sanitizer, registry: &scopeRegistry{ subscopes: make(map[string]*scope), @@ -171,7 +171,7 @@ func newRootScope(opts ScopeOptions, interval time.Duration) *scope { // NB(r): Take a copy of the tags on creation // so that it cannot be modified after set. - s.tags = s.copyAndSanitiseMap(opts.Tags) + s.tags = s.copyAndSanitizeMap(opts.Tags) // Register the root scope s.registry.subscopes[scopeRegistryKey(s.prefix, s.tags)] = s @@ -277,7 +277,7 @@ func (s *scope) reportRegistryWithLock() { } func (s *scope) Counter(name string) Counter { - name = s.sanitiser.Name(name) + name = s.sanitizer.Name(name) s.cm.RLock() val, ok := s.counters[name] s.cm.RUnlock() @@ -300,7 +300,7 @@ func (s *scope) Counter(name string) Counter { } func (s *scope) Gauge(name string) Gauge { - name = s.sanitiser.Name(name) + name = s.sanitizer.Name(name) s.gm.RLock() val, ok := s.gauges[name] s.gm.RUnlock() @@ -323,7 +323,7 @@ func (s *scope) Gauge(name string) Gauge { } func (s *scope) Timer(name string) Timer { - name = s.sanitiser.Name(name) + name = s.sanitizer.Name(name) s.tm.RLock() val, ok := s.timers[name] s.tm.RUnlock() @@ -348,7 +348,7 @@ func (s *scope) Timer(name string) Timer { } func (s *scope) Histogram(name string, b Buckets) Histogram { - name = s.sanitiser.Name(name) + name = s.sanitizer.Name(name) if b == nil { b = s.defaultBuckets @@ -378,12 +378,12 @@ func (s *scope) Histogram(name string, b Buckets) Histogram { } func (s *scope) Tagged(tags map[string]string) Scope { - tags = s.copyAndSanitiseMap(tags) + tags = s.copyAndSanitizeMap(tags) return s.subscope(s.prefix, tags) } func (s *scope) SubScope(prefix string) Scope { - prefix = s.sanitiser.Name(prefix) + prefix = s.sanitizer.Name(prefix) return s.subscope(s.fullyQualifiedName(prefix), nil) } @@ -417,7 +417,7 @@ func (s *scope) subscope(prefix string, immutableTags map[string]string) Scope { cachedReporter: s.cachedReporter, baseReporter: s.baseReporter, defaultBuckets: s.defaultBuckets, - sanitiser: s.sanitiser, + sanitizer: s.sanitizer, registry: s.registry, counters: make(map[string]*counter), @@ -521,26 +521,26 @@ func (s *scope) Close() error { return nil } -// NB(prateek): We assume concatenation of sanitised inputs is -// sanitised. If that stops being true, then we need to sanitise the +// NB(prateek): We assume concatenation of sanitized inputs is +// sanitized. If that stops being true, then we need to sanitize the // output of this function. func (s *scope) fullyQualifiedName(name string) string { if len(s.prefix) == 0 { return name } - // NB: we don't need to sanitise the output of this function as we - // sanitise all the the inputs (prefix, separator, name); and the - // output we're creating is a concatenation of the sanitised inputs. + // NB: we don't need to sanitize the output of this function as we + // sanitize all the the inputs (prefix, separator, name); and the + // output we're creating is a concatenation of the sanitized inputs. // If we change the concatenation to involve other inputs or characters, - // we'll need to sanitise them too. + // we'll need to sanitize them too. return fmt.Sprintf("%s%s%s", s.prefix, s.separator, name) } -func (s *scope) copyAndSanitiseMap(tags map[string]string) map[string]string { +func (s *scope) copyAndSanitizeMap(tags map[string]string) map[string]string { result := make(map[string]string, len(tags)) for k, v := range tags { - k = s.sanitiser.Key(k) - v = s.sanitiser.Value(v) + k = s.sanitizer.Key(k) + v = s.sanitizer.Value(v) result[k] = v } return result diff --git a/scope_benchmark_test.go b/scope_benchmark_test.go index eefe1bb6..214407de 100644 --- a/scope_benchmark_test.go +++ b/scope_benchmark_test.go @@ -55,11 +55,11 @@ func BenchmarkCounterAllocation(b *testing.B) { } } -func BenchmarkSanitisedCounterAllocation(b *testing.B) { +func BenchmarkSanitizedCounterAllocation(b *testing.B) { root, _ := NewRootScope(ScopeOptions{ Prefix: "funkytown", Reporter: NullStatsReporter, - SanitiseOptions: &alphanumericSanitiserOpts, + SanitizeOptions: &alphanumericSanitizerOpts, }, 0) s := root.(*scope) diff --git a/scope_test.go b/scope_test.go index e06d698f..2d800331 100644 --- a/scope_test.go +++ b/scope_test.go @@ -31,9 +31,9 @@ import ( ) var ( - // alphanumericSanitiserOpts is the options to create a sanitiser which uses - // the alphanumeric SanitiseFn. - alphanumericSanitiserOpts = SanitiseOptions{ + // alphanumericSanitizerOpts is the options to create a sanitizer which uses + // the alphanumeric SanitizeFn. + alphanumericSanitizerOpts = SanitizeOptions{ NameCharacters: ValidCharacters{ Ranges: AlphanumericRange, Characters: UnderscoreDashCharacters, @@ -365,12 +365,12 @@ func TestWriteOnce(t *testing.T) { assert.Nil(t, r.timers["ticky"]) } -func TestCounterSanitised(t *testing.T) { +func TestCounterSanitized(t *testing.T) { r := newTestStatsReporter() root, closer := NewRootScope(ScopeOptions{ Reporter: r, - SanitiseOptions: &alphanumericSanitiserOpts, + SanitizeOptions: &alphanumericSanitizerOpts, }, 0) defer closer.Close() @@ -595,7 +595,7 @@ func TestTaggedSubScope(t *testing.T) { }, r.histograms["foo.bar"].tags) } -func TestTaggedSanitisedSubScope(t *testing.T) { +func TestTaggedSanitizedSubScope(t *testing.T) { r := newTestStatsReporter() ts := map[string]string{"env": "test:env"} @@ -603,7 +603,7 @@ func TestTaggedSanitisedSubScope(t *testing.T) { Prefix: "foo", Tags: ts, Reporter: r, - SanitiseOptions: &alphanumericSanitiserOpts, + SanitizeOptions: &alphanumericSanitizerOpts, }, 0) defer closer.Close()