Skip to content

Commit

Permalink
View.New() miss InstrumentKind check (#3043)
Browse files Browse the repository at this point in the history
Signed-off-by: liupengfei <[email protected]>

Co-authored-by: Tyler Yahn <[email protected]>
  • Loading branch information
Petrie and MrAlias authored Jul 28, 2022
1 parent 590fff9 commit 26506aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sdk/metric/view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func New(opts ...Option) (View, error) {

emptyScope := instrumentation.Scope{}
if v.instrumentName == nil &&
v.scope == emptyScope {
v.scope == emptyScope &&
v.instrumentKind == undefinedInstrument {
return View{}, fmt.Errorf("must provide at least 1 match option")
}

Expand Down Expand Up @@ -119,6 +120,7 @@ func (v View) matchScopeVersion(version string) bool {
func (v View) matchScopeSchemaURL(schemaURL string) bool {
return v.scope.SchemaURL == "" || schemaURL == v.scope.SchemaURL
}

func (v View) matchInstrumentKind(kind InstrumentKind) bool {
return v.instrumentKind == undefinedInstrument || kind == v.instrumentKind
}
Expand Down
11 changes: 11 additions & 0 deletions sdk/metric/view/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var matchInstrument = Instrument{
SchemaURL: "stuff.test/",
},
Name: "foo",
Kind: SyncCounter,
Description: "",
}

Expand All @@ -45,6 +46,7 @@ var noMatchInstrument = Instrument{
},
Name: "notstuff",
Description: "",
Kind: undefinedInstrument,
}

var emptyDescription = Instrument{}
Expand Down Expand Up @@ -94,6 +96,13 @@ func TestViewTransformInstrument(t *testing.T) {
},
match: matchInstrument,
notMatch: emptyDescription,
}, {
name: "instrument kind",
options: []Option{
MatchInstrumentKind(SyncCounter),
},
match: matchInstrument,
notMatch: emptyDescription,
},
{
name: "Expands *",
Expand Down Expand Up @@ -130,6 +139,7 @@ func TestViewTransformInstrument(t *testing.T) {
},
Name: "baz",
Description: "",
Kind: SyncCounter,
},
notMatch: emptyDescription,
},
Expand All @@ -147,6 +157,7 @@ func TestViewTransformInstrument(t *testing.T) {
},
Name: "foo",
Description: "descriptive stuff",
Kind: SyncCounter,
},
notMatch: emptyDescription,
},
Expand Down

0 comments on commit 26506aa

Please sign in to comment.