-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GoogleCloudSpannerReceiver: Mask lock stats PII #14607
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
change_type: enhancement | ||
component: googlecloudspannerreceiver | ||
note: Configurably mask the PII in lock stats metrics. | ||
issues: [14607] | ||
subtext: |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ package metadata // import "github.com/open-telemetry/opentelemetry-collector-co | |
|
||
import ( | ||
"fmt" | ||
"hash/fnv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/mitchellh/hashstructure" | ||
|
@@ -114,6 +116,44 @@ func (mdp *MetricsDataPoint) toDataForHashing() dataForHashing { | |
} | ||
} | ||
|
||
// Convert row_range_start_key label of top-lock-stats metric from format "sample(key1, key2)" to "sample(hash1, hash2)" | ||
func parseAndHashRowrangestartkey(key string) string { | ||
startIndexKeys := strings.Index(key, "(") | ||
substring := key[startIndexKeys+1 : len(key)-1] | ||
hashedKey := key[:startIndexKeys+1] | ||
plusPresent := false | ||
if substring[len(substring)-1] == '+' { | ||
substring = substring[:len(substring)-1] | ||
plusPresent = true | ||
} | ||
keySlice := strings.Split(substring, ",") | ||
hashFunction := fnv.New32a() | ||
for _, subKey := range keySlice { | ||
hashFunction.Reset() | ||
hashFunction.Write([]byte(subKey)) | ||
hashedKey += fmt.Sprint(hashFunction.Sum32()) + "," | ||
} | ||
hashedKey = hashedKey[:len(hashedKey)-1] | ||
if plusPresent { | ||
hashedKey += "+" | ||
} | ||
hashedKey += ")" | ||
return hashedKey | ||
} | ||
|
||
func (mdp *MetricsDataPoint) HideLockStatsRowrangestartkeyPII() { | ||
for index, labelValue := range mdp.labelValues { | ||
if labelValue.Metadata().Name() == "row_range_start_key" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this label available on a single metric or on multiple metrics? (Trying to figure out how the configuration should look like) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This label is available on a single metric. |
||
key := labelValue.Value().(string) | ||
hashedKey := parseAndHashRowrangestartkey(key) | ||
v := mdp.labelValues[index].(byteSliceLabelValue) | ||
p := &v | ||
p.ModifyValue(hashedKey) | ||
mdp.labelValues[index] = v | ||
} | ||
} | ||
} | ||
|
||
func (mdp *MetricsDataPoint) hash() (string, error) { | ||
hashedData, err := hashstructure.Hash(mdp.toDataForHashing(), nil) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest using a strings.Builder here for performance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done . Updated PR is at #16343 because this one got closed because of inactivity