fix (telemetry): ignore fields without public class
This commit is contained in:
1 parent
9413837b6a
commit
f13a23eab7
2 files changed
+29
-8
No files matched your search
@@ -30,7 +30,7 @@ type protoFilter func(field reflect.StructField) bool
|
||||
|
||||
// telemetryFilter checks a struct field should be included in observation telemetry data
|
||||
func telemetryFilter(field reflect.StructField) bool {
|
||||
if field.Tag.Get("eventstream") == "observation" {
|
||||
if field.Tag.Get("eventstream") == "observation" && field.Tag.Get("class") == "public" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -115,7 +115,7 @@ func Test_scalarSliceFilterAllZeroVals(t *testing.T) {
|
||||
assert := tassert.New(t)
|
||||
type testType struct {
|
||||
NonObservableStrings []string
|
||||
ObservableInts []int `eventstream:"observation"`
|
||||
ObservableInts []int `eventstream:"observation" class:"public"`
|
||||
}
|
||||
data := &testType{
|
||||
NonObservableStrings: []string{"a", "b", "c"},
|
||||
@@ -131,7 +131,7 @@ func Test_mapFilter(t *testing.T) {
|
||||
assert := tassert.New(t)
|
||||
type testType struct {
|
||||
NonObservableMap map[string]int
|
||||
ObservableMap map[string]int `eventstream:"observation"`
|
||||
ObservableMap map[string]int `eventstream:"observation" class:"public"`
|
||||
}
|
||||
data := &testType{
|
||||
NonObservableMap: map[string]int{
|
||||
@@ -160,11 +160,11 @@ func Test_coreProtoTypes(t *testing.T) {
|
||||
assert := tassert.New(t)
|
||||
type testType struct {
|
||||
Timestamp *timestamppb.Timestamp
|
||||
TimestampObs *timestamppb.Timestamp `eventstream:"observation"`
|
||||
TimestampObs *timestamppb.Timestamp `eventstream:"observation" class:"public"`
|
||||
WrappedString *wrapperspb.StringValue
|
||||
WrappedStringObs *wrapperspb.StringValue `eventstream:"observation"`
|
||||
WrappedStringObs *wrapperspb.StringValue `eventstream:"observation" class:"public"`
|
||||
Fieldmask *fieldmaskpb.FieldMask
|
||||
FieldmaskObs *fieldmaskpb.FieldMask `eventstream:"observation"`
|
||||
FieldmaskObs *fieldmaskpb.FieldMask `eventstream:"observation" class:"public"`
|
||||
}
|
||||
data := &testType{
|
||||
Timestamp: ×tamppb.Timestamp{
|
||||
@@ -206,7 +206,7 @@ func Test_mapStructPBValues(t *testing.T) {
|
||||
assert := tassert.New(t)
|
||||
type testType struct {
|
||||
ListValueMap map[string]*structpb.ListValue
|
||||
ListValueMapObs map[string]*structpb.ListValue `eventstream:"observation"`
|
||||
ListValueMapObs map[string]*structpb.ListValue `eventstream:"observation" class:"public"`
|
||||
}
|
||||
data := &testType{
|
||||
ListValueMap: map[string]*structpb.ListValue{
|
||||
@@ -256,7 +256,7 @@ func Test_sliceStructPBValues(t *testing.T) {
|
||||
assert := tassert.New(t)
|
||||
type testType struct {
|
||||
ListValueSlice []*structpb.ListValue
|
||||
ListValueSliceObs []*structpb.ListValue `eventstream:"observation"`
|
||||
ListValueSliceObs []*structpb.ListValue `eventstream:"observation" class:"public"`
|
||||
ListValueArray [2]*structpb.ListValue
|
||||
}
|
||||
data := &testType{
|
||||
@@ -313,3 +313,24 @@ func Test_sliceStructPBValues(t *testing.T) {
|
||||
assert.Nil(data.ListValueArray[0])
|
||||
assert.Nil(data.ListValueArray[1])
|
||||
}
|
||||
|
||||
func Test_onlyPublicTelemetryFields(t *testing.T) {
|
||||
assert := tassert.New(t)
|
||||
type testType struct {
|
||||
NonObservableString string
|
||||
NonPublicObservableString string `eventstream:"observation"`
|
||||
PublicObservableString string `eventstream:"observation" class:"public"`
|
||||
SecretObservableString string `eventstream:"observation" class:"secret"`
|
||||
}
|
||||
data := &testType{
|
||||
NonObservableString: "empty",
|
||||
NonPublicObservableString: "empty",
|
||||
PublicObservableString: "observable",
|
||||
SecretObservableString: "empty",
|
||||
}
|
||||
err := recurseStructureWithProtoFilter(reflect.ValueOf(data), telemetryFilter, false)
|
||||
assert.NoError(err)
|
||||
assert.Equal(&testType{
|
||||
PublicObservableString: "observable",
|
||||
}, data)
|
||||
}
|
||||
Reference in new issue
Block a user