Skip to content

Commit

Permalink
Ensure exported interfaces have named method parameters (#1172)
Browse files Browse the repository at this point in the history
* Ensure exported interface types have named arguments

* Update Styling Guide

* update CHANGELOG
  • Loading branch information
matej-g committed Sep 16, 2020
1 parent 2621bd4 commit a12224a
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -39,6 +39,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The [configuration style guide](https://github.com/open-telemetry/opentelemetry-go/blob/master/CONTRIBUTING.md#config) has been updated to
recommend the use of `newConfig()` instead of `configure()`. (#1163)
- The `otlp.Config` type has been unexported and changed to `otlp.config`, along with its initializer. (#1163)
- Ensure exported interface types include parameter names and update the
Style Guide to reflect this styling rule. (#1172)
- Don't consider unset environment variable for resource detection to be an error. (#1170)
- Rename `go.opentelemetry.io/otel/api/metric.ConfigureInstrument` to `NewInstrumentConfig` and
`go.opentelemetry.io/otel/api/metric.ConfigureMeter` to `NewMeterConfig`.
Expand Down
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -345,6 +345,14 @@ func NewDog(name string, o ...DogOption) Dog {…}
func NewBird(name string, o ...BirdOption) Bird {…}
```

### Interface Type

To allow other developers to better comprehend the code, it is important
to ensure it is sufficiently documented. One simple measure that contributes
to this aim is self-documenting by naming method parameters. Therefore,
where appropriate, methods of every exported interface type should have
their parameters appropriately named.

## Approvers and Maintainers

Approvers:
Expand Down
4 changes: 2 additions & 2 deletions api/metric/metrictest/async.go
Expand Up @@ -32,7 +32,7 @@ var ErrInvalidAsyncRunner = errors.New("unknown async runner type")
// the SDK to provide support for running observer callbacks.
type AsyncCollector interface {
// CollectAsync passes a batch of observations to the MeterImpl.
CollectAsync([]label.KeyValue, ...metric.Observation)
CollectAsync(labels []label.KeyValue, observation ...metric.Observation)
}

// AsyncInstrumentState manages an ordered set of asynchronous
Expand All @@ -49,7 +49,7 @@ type AsyncInstrumentState struct {
// collection interval. Singletons are entered with a real
// instrument each, batch observers are entered with a nil
// instrument, ensuring that when a singleton callback is used
// repeatedly, it is excuted repeatedly in the interval, while
// repeatedly, it is executed repeatedly in the interval, while
// when a batch callback is used repeatedly, it only executes
// once per interval.
runnerMap map[asyncRunnerPair]struct{}
Expand Down
6 changes: 3 additions & 3 deletions api/metric/sdkapi.go
Expand Up @@ -24,7 +24,7 @@ import (
// implementation.
type MeterImpl interface {
// RecordBatch atomically records a batch of measurements.
RecordBatch(context.Context, []label.KeyValue, ...Measurement)
RecordBatch(ctx context.Context, labels []label.KeyValue, measurement ...Measurement)

// NewSyncInstrument returns a newly constructed
// synchronous instrument implementation or an error, should
Expand Down Expand Up @@ -85,10 +85,10 @@ type AsyncImpl interface {

// WrapMeterImpl constructs a `Meter` implementation from a
// `MeterImpl` implementation.
func WrapMeterImpl(impl MeterImpl, instrumentatioName string, opts ...MeterOption) Meter {
func WrapMeterImpl(impl MeterImpl, instrumentationName string, opts ...MeterOption) Meter {
return Meter{
impl: impl,
name: instrumentatioName,
name: instrumentationName,
version: NewMeterConfig(opts...).InstrumentationVersion,
}
}
4 changes: 2 additions & 2 deletions api/propagation/propagation.go
Expand Up @@ -43,7 +43,7 @@ type HTTPExtractor interface {
// trace.ContextWithRemoteSpanContext. In case of correlation
// context, the propagator should use correlation.WithMap to
// store it in the context.
Extract(context.Context, HTTPSupplier) context.Context
Extract(ctx context.Context, supplier HTTPSupplier) context.Context
}

// HTTPInjector injects information into a HTTPSupplier.
Expand All @@ -52,7 +52,7 @@ type HTTPInjector interface {
// encodes it into propagator specific format and then injects
// the encoded information using supplier into an associated
// carrier.
Inject(context.Context, HTTPSupplier)
Inject(ctx context.Context, supplier HTTPSupplier)
}

// Config contains the current set of extractors and injectors.
Expand Down
4 changes: 2 additions & 2 deletions api/trace/tracetest/config.go
Expand Up @@ -89,8 +89,8 @@ func WithSpanRecorder(sr SpanRecorder) Option {
}

type SpanRecorder interface {
OnStart(*Span)
OnEnd(*Span)
OnStart(span *Span)
OnEnd(span *Span)
}

type StandardSpanRecorder struct {
Expand Down
2 changes: 1 addition & 1 deletion bridge/opentracing/migration/api.go
Expand Up @@ -72,5 +72,5 @@ type OverrideTracerSpanExtension interface {
// API calls. In such case, there is no need to use the
// WrapperTracer and thus no need to override the result of
// the Tracer() function.
OverrideTracer(oteltrace.Tracer)
OverrideTracer(tracer oteltrace.Tracer)
}
2 changes: 1 addition & 1 deletion label/encoder.go
Expand Up @@ -29,7 +29,7 @@ type (
// Encode returns the serialized encoding of the label
// set using its Iterator. This result may be cached
// by a label.Set.
Encode(Iterator) string
Encode(iterator Iterator) string

// ID returns a value that is unique for each class of
// label encoder. Label encoders allocate these using
Expand Down
14 changes: 7 additions & 7 deletions sdk/export/metric/metric.go
Expand Up @@ -71,7 +71,7 @@ type Processor interface {
// computation. An SDK is not expected to call exporters from
// with Process, use a controller for that (see
// ./controllers/{pull,push}.
Process(Accumulation) error
Process(accum Accumulation) error
}

// AggregatorSelector supports selecting the kind of Aggregator to
Expand All @@ -94,7 +94,7 @@ type AggregatorSelector interface {
// Note: This is context-free because the aggregator should
// not relate to the incoming context. This call should not
// block.
AggregatorFor(*metric.Descriptor, ...*Aggregator)
AggregatorFor(descriptor *metric.Descriptor, aggregator ...*Aggregator)
}

// Checkpointer is the interface used by a Controller to coordinate
Expand Down Expand Up @@ -152,7 +152,7 @@ type Aggregator interface {
//
// The Context argument comes from user-level code and could be
// inspected for a `correlation.Map` or `trace.SpanContext`.
Update(context.Context, metric.Number, *metric.Descriptor) error
Update(ctx context.Context, number metric.Number, descriptor *metric.Descriptor) error

// SynchronizedMove is called during collection to finish one
// period of aggregation by atomically saving the
Expand Down Expand Up @@ -181,7 +181,7 @@ type Aggregator interface {
//
// The owner of an Aggregator being merged is responsible for
// synchronization of both Aggregator states.
Merge(Aggregator, *metric.Descriptor) error
Merge(aggregator Aggregator, descriptor *metric.Descriptor) error
}

// Subtractor is an optional interface implemented by some
Expand All @@ -206,7 +206,7 @@ type Exporter interface {
//
// The CheckpointSet interface refers to the Processor that just
// completed collection.
Export(context.Context, CheckpointSet) error
Export(ctx context.Context, checkpointSet CheckpointSet) error

// ExportKindSelector is an interface used by the Processor
// in deciding whether to compute Delta or Cumulative
Expand All @@ -221,7 +221,7 @@ type ExportKindSelector interface {
// ExportKindFor should return the correct ExportKind that
// should be used when exporting data for the given metric
// instrument and Aggregator kind.
ExportKindFor(*metric.Descriptor, aggregation.Kind) ExportKind
ExportKindFor(descriptor *metric.Descriptor, aggregatorKind aggregation.Kind) ExportKind
}

// CheckpointSet allows a controller to access a complete checkpoint of
Expand All @@ -242,7 +242,7 @@ type CheckpointSet interface {
// expected from the Meter implementation. Any other kind
// of error will immediately halt ForEach and return
// the error to the caller.
ForEach(ExportKindSelector, func(Record) error) error
ForEach(kindSelector ExportKindSelector, recordFunc func(Record) error) error

// Locker supports locking the checkpoint set. Collection
// into the checkpoint set cannot take place (in case of a
Expand Down
4 changes: 2 additions & 2 deletions sdk/export/trace/trace.go
Expand Up @@ -40,12 +40,12 @@ type SpanExporter interface {
// calls this function will not implement any retry logic. All errors
// returned by this function are considered unrecoverable and will be
// reported to a configured error Handler.
ExportSpans(context.Context, []*SpanData) error
ExportSpans(ctx context.Context, spanData []*SpanData) error
// Shutdown notifies the exporter of a pending halt to operations. The
// exporter is expected to preform any cleanup or synchronization it
// requires while honoring all timeouts and cancellations contained in
// the passed context.
Shutdown(context.Context) error
Shutdown(ctx context.Context) error
}

// SpanData contains all the information collected by a completed span.
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/controller/time/time.go
Expand Up @@ -24,7 +24,7 @@ import (

type Clock interface {
Now() lib.Time
Ticker(lib.Duration) Ticker
Ticker(duration lib.Duration) Ticker
}

type Ticker interface {
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/processor/reducer/reducer.go
Expand Up @@ -31,7 +31,7 @@ type (
// LabelFilterSelector is the interface used to configure a
// specific Filter to an instrument.
LabelFilterSelector interface {
LabelFilterFor(*metric.Descriptor) label.Filter
LabelFilterFor(descriptor *metric.Descriptor) label.Filter
}
)

Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/sampling.go
Expand Up @@ -24,7 +24,7 @@ import (

// Sampler decides whether a trace should be sampled and exported.
type Sampler interface {
ShouldSample(SamplingParameters) SamplingResult
ShouldSample(parameters SamplingParameters) SamplingResult
Description() string
}

Expand Down

0 comments on commit a12224a

Please sign in to comment.