Skip to content

Commit

Permalink
Fix exported instrument kind const value change (#5385)
Browse files Browse the repository at this point in the history
#5304 introduced the following incompatible changes:

- `InstrumentKindObservableCounter`: value changed from 4 to 5
- `InstrumentKindObservableGauge`: value changed from 6 to 7
- `InstrumentKindObservableUpDownCounter`: value changed from 5 to 6

This reverts that change, making `InstrumentKindGauge` explicitly `7`.

Additionally, this removes the use of `iota` to prevent this kind of
breaking change from being accidentally introduced in the future.
  • Loading branch information
MrAlias committed May 21, 2024
1 parent 7aae7a8 commit 0d3dddc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
22 changes: 11 additions & 11 deletions sdk/metric/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,32 @@ type InstrumentKind uint8
const (
// instrumentKindUndefined is an undefined instrument kind, it should not
// be used by any initialized type.
instrumentKindUndefined InstrumentKind = iota // nolint:deadcode,varcheck,unused
instrumentKindUndefined InstrumentKind = 0 // nolint:deadcode,varcheck,unused
// InstrumentKindCounter identifies a group of instruments that record
// increasing values synchronously with the code path they are measuring.
InstrumentKindCounter
InstrumentKindCounter InstrumentKind = 1
// InstrumentKindUpDownCounter identifies a group of instruments that
// record increasing and decreasing values synchronously with the code path
// they are measuring.
InstrumentKindUpDownCounter
InstrumentKindUpDownCounter InstrumentKind = 2
// InstrumentKindHistogram identifies a group of instruments that record a
// distribution of values synchronously with the code path they are
// measuring.
InstrumentKindHistogram
// InstrumentKindGauge identifies a group of instruments that record
// instantaneous values synchronously with the code path they are
// measuring.
InstrumentKindGauge
InstrumentKindHistogram InstrumentKind = 3
// InstrumentKindObservableCounter identifies a group of instruments that
// record increasing values in an asynchronous callback.
InstrumentKindObservableCounter
InstrumentKindObservableCounter InstrumentKind = 4
// InstrumentKindObservableUpDownCounter identifies a group of instruments
// that record increasing and decreasing values in an asynchronous
// callback.
InstrumentKindObservableUpDownCounter
InstrumentKindObservableUpDownCounter InstrumentKind = 5
// InstrumentKindObservableGauge identifies a group of instruments that
// record current values in an asynchronous callback.
InstrumentKindObservableGauge
InstrumentKindObservableGauge InstrumentKind = 6
// InstrumentKindGauge identifies a group of instruments that record
// instantaneous values synchronously with the code path they are
// measuring.
InstrumentKindGauge InstrumentKind = 7
)

type nonComparable [0]func() // nolint: unused // This is indeed used.
Expand Down
12 changes: 6 additions & 6 deletions sdk/metric/instrumentkind_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions sdk/metric/pipeline_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ func testCreateAggregators[N int64 | float64](t *testing.T) {
)

instruments := []Instrument{
{Name: "foo", Kind: InstrumentKind(0)}, // Unknown kind
{Name: "foo", Kind: InstrumentKindCounter},
{Name: "foo", Kind: InstrumentKindUpDownCounter},
{Name: "foo", Kind: InstrumentKindHistogram},
{Name: "foo", Kind: InstrumentKindGauge},
{Name: "foo", Kind: InstrumentKindObservableCounter},
{Name: "foo", Kind: InstrumentKindObservableUpDownCounter},
{Name: "foo", Kind: InstrumentKindObservableGauge},
InstrumentKind(0): {Name: "foo", Kind: InstrumentKind(0)}, // Unknown kind
InstrumentKindCounter: {Name: "foo", Kind: InstrumentKindCounter},
InstrumentKindUpDownCounter: {Name: "foo", Kind: InstrumentKindUpDownCounter},
InstrumentKindHistogram: {Name: "foo", Kind: InstrumentKindHistogram},
InstrumentKindGauge: {Name: "foo", Kind: InstrumentKindGauge},
InstrumentKindObservableCounter: {Name: "foo", Kind: InstrumentKindObservableCounter},
InstrumentKindObservableUpDownCounter: {Name: "foo", Kind: InstrumentKindObservableUpDownCounter},
InstrumentKindObservableGauge: {Name: "foo", Kind: InstrumentKindObservableGauge},
}

testcases := []struct {
Expand Down

0 comments on commit 0d3dddc

Please sign in to comment.