Skip to content

Commit

Permalink
Lint fixes LS metrics SDK (#759)
Browse files Browse the repository at this point in the history
**Description:** `Library` to `Scope`
  • Loading branch information
jmacd authored Sep 6, 2024
1 parent 6c1cf4b commit 92d9901
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lightstep/sdk/metric/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type (
// See the comments on Metrics about re-use of slices in this struct.
Scope struct {
// Library describes the instrumentation scope.
Library instrumentation.Library
Library instrumentation.Scope

// Instruments is a slice of metric data, one per Instrument
// in the scope.
Expand Down
2 changes: 1 addition & 1 deletion lightstep/sdk/metric/internal/asyncstate/async_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
)

var (
testLibrary = instrumentation.Library{
testLibrary = instrumentation.Scope{
Name: "test",
}

Expand Down
26 changes: 13 additions & 13 deletions lightstep/sdk/metric/internal/syncstate/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func testSyncStateConcurrencyWithPerf[N number.Any, Traits number.Traits[N]](t *
readers.Add(numReaders)
writers.Add(numRoutines)

lib := instrumentation.Library{
lib := instrumentation.Scope{
Name: "testlib",
}
vcs := make([]*viewstate.Compiler, numReaders)
Expand Down Expand Up @@ -273,7 +273,7 @@ func TestSyncStatePartialNoopInstrument(t *testing.T) {
view.WithAggregation(aggregation.DropKind),
),
}
lib := instrumentation.Library{
lib := instrumentation.Scope{
Name: "testlib",
}
vcs := make([]*viewstate.Compiler, 2)
Expand Down Expand Up @@ -342,7 +342,7 @@ func TestSyncStateFullNoopInstrument(t *testing.T) {
view.WithAggregation(aggregation.DropKind),
),
}
lib := instrumentation.Library{
lib := instrumentation.Scope{
Name: "testlib",
}
vcs := make([]*viewstate.Compiler, 2)
Expand Down Expand Up @@ -382,7 +382,7 @@ func TestOutOfRangeValues(t *testing.T) {
test.Descriptor("hi", sdkinstrument.SyncHistogram, number.Int64Kind),
} {
ctx := context.Background()
lib := instrumentation.Library{
lib := instrumentation.Scope{
Name: "testlib",
}
vcs := make([]*viewstate.Compiler, 1)
Expand Down Expand Up @@ -460,7 +460,7 @@ func TestOutOfRangeValues(t *testing.T) {

func TestSyncGaugeDeltaInstrument(t *testing.T) {
ctx := context.Background()
lib := instrumentation.Library{
lib := instrumentation.Scope{
Name: "testlib",
}
vcs := make([]*viewstate.Compiler, 2)
Expand Down Expand Up @@ -760,7 +760,7 @@ func TestFingerprintCollision(t *testing.T) {

func TestDuplicateFingerprintSafety(t *testing.T) {
ctx := context.Background()
lib := instrumentation.Library{
lib := instrumentation.Scope{
Name: "testlib",
}
vcs := make([]*viewstate.Compiler, 2)
Expand Down Expand Up @@ -959,7 +959,7 @@ func TestDuplicateFingerprintSafety(t *testing.T) {

func TestDuplicateFingerprintCollisionIgnored(t *testing.T) {
ctx := context.Background()
lib := instrumentation.Library{
lib := instrumentation.Scope{
Name: "testlib",
}
vcs := make([]*viewstate.Compiler, 1)
Expand Down Expand Up @@ -1057,7 +1057,7 @@ func TestRecordInactivity(t *testing.T) {
for inactive := uint32(1); inactive < 10; inactive++ {
t.Run(fmt.Sprint(inactive), func(t *testing.T) {
ctx := context.Background()
lib := instrumentation.Library{
lib := instrumentation.Scope{
Name: "testlib",
}
vcs := make([]*viewstate.Compiler, 1)
Expand Down Expand Up @@ -1167,7 +1167,7 @@ func TestCardinalityOverflowCumulative(t *testing.T) {
const limit = 133

ctx := context.Background()
lib := instrumentation.Library{
lib := instrumentation.Scope{
Name: "testlib",
}
perf := sdkinstrument.Performance{
Expand Down Expand Up @@ -1259,7 +1259,7 @@ func TestCardinalityOverflowAvoidedDelta(t *testing.T) {
const limit = 100 // has to be even

ctx := context.Background()
lib := instrumentation.Library{
lib := instrumentation.Scope{
Name: "testlib",
}
perf := sdkinstrument.Performance{
Expand Down Expand Up @@ -1326,7 +1326,7 @@ func TestCardinalityOverflowOscillationDelta(t *testing.T) {
const limit = 4

ctx := context.Background()
lib := instrumentation.Library{
lib := instrumentation.Scope{
Name: "testlib",
}
perf := sdkinstrument.Performance{
Expand Down Expand Up @@ -1405,7 +1405,7 @@ func TestCardinalityOverflowOscillationDelta(t *testing.T) {

func TestInputAttributeSliceRaceCondition(t *testing.T) {
ctx := context.Background()
lib := instrumentation.Library{
lib := instrumentation.Scope{
Name: "testlib",
}
perf := sdkinstrument.Performance{}
Expand Down Expand Up @@ -1454,7 +1454,7 @@ func TestInputAttributeSliceRaceCondition(t *testing.T) {

func TestAttributeSizeLimit(t *testing.T) {
ctx := context.Background()
lib := instrumentation.Library{
lib := instrumentation.Scope{
Name: "testlib",
}
// This enters a default value
Expand Down
6 changes: 3 additions & 3 deletions lightstep/sdk/metric/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ func Instrument(desc sdkinstrument.Descriptor, points ...data.Point) data.Instru
}
}

func Library(name string, opts ...metric.MeterOption) instrumentation.Library {
func Library(name string, opts ...metric.MeterOption) instrumentation.Scope {
cfg := metric.NewMeterConfig(opts...)
return instrumentation.Library{
return instrumentation.Scope{
Name: name,
Version: cfg.InstrumentationVersion(),
SchemaURL: cfg.SchemaURL(),
}
}

func Scope(library instrumentation.Library, insts ...data.Instrument) data.Scope {
func Scope(library instrumentation.Scope, insts ...data.Instrument) data.Scope {
return data.Scope{
Library: library,
Instruments: insts,
Expand Down
4 changes: 2 additions & 2 deletions lightstep/sdk/metric/internal/viewstate/viewstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Compiler struct {

// library is the value used fr matching
// instrumentation library information.
library instrumentation.Library
library instrumentation.Scope

// lock protects collectors and names.
compilerLock sync.Mutex
Expand Down Expand Up @@ -177,7 +177,7 @@ type singleBehavior struct {
}

// New returns a compiler for library given configured views.
func New(library instrumentation.Library, views *view.Views) *Compiler {
func New(library instrumentation.Scope, views *view.Views) *Compiler {
views, _ = view.Validate(views)
return &Compiler{
library: library,
Expand Down
2 changes: 1 addition & 1 deletion lightstep/sdk/metric/internal/viewstate/viewstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
)

var (
testLib = instrumentation.Library{
testLib = instrumentation.Scope{
Name: "test",
}

Expand Down
2 changes: 1 addition & 1 deletion lightstep/sdk/metric/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type (
meter struct {
embedded.Meter

library instrumentation.Library
library instrumentation.Scope
provider *MeterProvider
compilers pipeline.Register[*viewstate.Compiler]

Expand Down
6 changes: 3 additions & 3 deletions lightstep/sdk/metric/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type MeterProvider struct {
lock sync.Mutex
ordered []*meter
views []*view.Views
meters map[instrumentation.Library]*meter
meters map[instrumentation.Scope]*meter
}

// Compile-time check MeterProvider implements metric.MeterProvider.
Expand All @@ -71,7 +71,7 @@ func NewMeterProvider(options ...Option) *MeterProvider {
p := &MeterProvider{
cfg: cfg,
startTime: time.Now(),
meters: map[instrumentation.Library]*meter{},
meters: map[instrumentation.Scope]*meter{},
}
for pipe := 0; pipe < len(cfg.readers); pipe++ {
r := cfg.readers[pipe]
Expand Down Expand Up @@ -102,7 +102,7 @@ func NewMeterProvider(options ...Option) *MeterProvider {
// This method is safe to call concurrently.
func (mp *MeterProvider) Meter(name string, options ...metric.MeterOption) metric.Meter {
cfg := metric.NewMeterConfig(options...)
lib := instrumentation.Library{
lib := instrumentation.Scope{
Name: name,
Version: cfg.InstrumentationVersion(),
SchemaURL: cfg.SchemaURL(),
Expand Down
8 changes: 4 additions & 4 deletions lightstep/sdk/metric/view/clause.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type ClauseConfig struct {
instrumentNameRegexp *regexp.Regexp
instrumentKind sdkinstrument.Kind
numberKind number.Kind
library instrumentation.Library
library instrumentation.Scope

// Properties of the view
keys []attribute.Key // nil implies all keys, []attribute.Key{} implies none
Expand Down Expand Up @@ -93,7 +93,7 @@ func MatchNumberKind(k number.Kind) ClauseOption {
})
}

func MatchInstrumentationLibrary(lib instrumentation.Library) ClauseOption {
func MatchInstrumentationLibrary(lib instrumentation.Scope) ClauseOption {
return clauseOptionFunction(func(clause ClauseConfig) ClauseConfig {
clause.library = lib
return clause
Expand Down Expand Up @@ -187,7 +187,7 @@ func regexpMismatch(test *regexp.Regexp, value string) bool {
return test != nil && !test.MatchString(value)
}

func (c *ClauseConfig) libraryMismatch(lib instrumentation.Library) bool {
func (c *ClauseConfig) libraryMismatch(lib instrumentation.Scope) bool {
hasName := c.library.Name != ""
hasVersion := c.library.Version != ""
hasSchema := c.library.SchemaURL != ""
Expand All @@ -200,7 +200,7 @@ func (c *ClauseConfig) libraryMismatch(lib instrumentation.Library) bool {
stringMismatch(c.library.SchemaURL, lib.SchemaURL)
}

func (c *ClauseConfig) Matches(lib instrumentation.Library, desc sdkinstrument.Descriptor) bool {
func (c *ClauseConfig) Matches(lib instrumentation.Scope, desc sdkinstrument.Descriptor) bool {
mismatch := c.libraryMismatch(lib) ||
stringMismatch(c.instrumentName, desc.Name) ||
ikindMismatch(c.instrumentKind, desc.Kind) ||
Expand Down
6 changes: 3 additions & 3 deletions lightstep/sdk/metric/view/views_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ var safePerf sdkinstrument.Performance

func TestClauseMatches(t *testing.T) {
re := regexp.MustCompile("s.+")
lib0 := instrumentation.Library{
lib0 := instrumentation.Scope{
Name: "fancy",
}
lib1 := instrumentation.Library{
lib1 := instrumentation.Scope{
Name: "limited",
Version: "vF.G.H",
}
Expand All @@ -48,7 +48,7 @@ func TestClauseMatches(t *testing.T) {
WithClause(MatchNumberKind(number.Float64Kind)),
WithClause(MatchInstrumentationLibrary(lib0)),
WithClause(
MatchInstrumentationLibrary(instrumentation.Library{Version: "vF.G.H"}),
MatchInstrumentationLibrary(instrumentation.Scope{Version: "vF.G.H"}),
MatchInstrumentKind(sdkinstrument.AsyncGauge),
),
)
Expand Down

0 comments on commit 92d9901

Please sign in to comment.