Skip to content

Commit

Permalink
[chore] [internal/attraction] Remove stable feature gate (#31997)
Browse files Browse the repository at this point in the history
Remove `coreinternal.attraction.hash.sha256` feature gate
  • Loading branch information
dmitryax authored Mar 27, 2024
1 parent 6d74e53 commit f29d215
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 79 deletions.
20 changes: 20 additions & 0 deletions .chloggen/remove-coreinternal-attraction-hash-sha256-fg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: processor/attributes, processor/resource

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove stable coreinternal.attraction.hash.sha256 feature gate.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [31997]

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
14 changes: 1 addition & 13 deletions internal/coreinternal/attraction/attraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,10 @@ import (
"strings"

"go.opentelemetry.io/collector/client"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.uber.org/zap"
)

var enableSha256Gate = featuregate.GlobalRegistry().MustRegister(
"coreinternal.attraction.hash.sha256",
featuregate.StageStable,
featuregate.WithRegisterDescription("When enabled, switches hashing algorithm from SHA-1 to SHA-2 256"),
featuregate.WithRegisterToVersion("0.85.0"),
)

// Settings specifies the processor settings.
type Settings struct {
// Actions specifies the list of attributes to act on.
Expand Down Expand Up @@ -404,11 +396,7 @@ func getSourceAttributeValue(ctx context.Context, action attributeAction, attrs

func hashAttribute(key string, attrs pcommon.Map) {
if value, exists := attrs.Get(key); exists {
if enableSha256Gate.IsEnabled() {
sha2Hasher(value)
} else {
sha1Hasher(value)
}
sha2Hasher(value)
}
}

Expand Down
15 changes: 0 additions & 15 deletions internal/coreinternal/attraction/attraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package attraction

import (
"context"
"crypto/sha1" // #nosec
"crypto/sha256"
"encoding/binary"
"errors"
Expand Down Expand Up @@ -930,20 +929,6 @@ func TestValidConfiguration(t *testing.T) {
}

func hash(b []byte) string {
if enableSha256Gate.IsEnabled() {
return sha2Hash(b)
}
return sha1Hash(b)
}

func sha1Hash(b []byte) string {
// #nosec
h := sha1.New()
h.Write(b)
return fmt.Sprintf("%x", h.Sum(nil))
}

func sha2Hash(b []byte) string {
h := sha256.New()
h.Write(b)
return fmt.Sprintf("%x", h.Sum(nil))
Expand Down
39 changes: 0 additions & 39 deletions internal/coreinternal/attraction/hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package attraction // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/attraction"

import (
"crypto/sha1" // #nosec
"crypto/sha256"
"encoding/binary"
"encoding/hex"
Expand All @@ -23,44 +22,6 @@ var (
byteFalse = [1]byte{0}
)

// Deprecated: [v0.75.0] use sha2Hasher instead.
// sha1Hasher hashes an AttributeValue using SHA1 and returns a
// hashed version of the attribute. In practice, this would mostly be used
// for string attributes but we support all types for completeness/correctness
// and eliminate any surprises.
func sha1Hasher(attr pcommon.Value) {
var val []byte
switch attr.Type() {
case pcommon.ValueTypeStr:
val = []byte(attr.Str())
case pcommon.ValueTypeBool:
if attr.Bool() {
val = byteTrue[:]
} else {
val = byteFalse[:]
}
case pcommon.ValueTypeInt:
val = make([]byte, int64ByteSize)
binary.LittleEndian.PutUint64(val, uint64(attr.Int()))
case pcommon.ValueTypeDouble:
val = make([]byte, float64ByteSize)
binary.LittleEndian.PutUint64(val, math.Float64bits(attr.Double()))
}

var hashed string
if len(val) > 0 {
// #nosec
h := sha1.New()
_, _ = h.Write(val)
val = h.Sum(nil)
hashedBytes := make([]byte, hex.EncodedLen(len(val)))
hex.Encode(hashedBytes, val)
hashed = string(hashedBytes)
}

attr.SetStr(hashed)
}

// sha2Hasher hashes an AttributeValue using SHA2-256 and returns a
// hashed version of the attribute. In practice, this would mostly be used
// for string attributes but we support all types for completeness/correctness
Expand Down
2 changes: 0 additions & 2 deletions internal/coreinternal/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
go.opentelemetry.io/collector v0.97.0
go.opentelemetry.io/collector/component v0.97.0
go.opentelemetry.io/collector/consumer v0.97.0
go.opentelemetry.io/collector/featuregate v1.4.0
go.opentelemetry.io/collector/pdata v1.4.0
go.opentelemetry.io/collector/receiver v0.97.0
go.opentelemetry.io/collector/semconv v0.97.0
Expand Down Expand Up @@ -46,7 +45,6 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.2 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
Expand Down
4 changes: 0 additions & 4 deletions internal/coreinternal/go.sum

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

2 changes: 0 additions & 2 deletions processor/resourceprocessor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
Expand All @@ -44,7 +43,6 @@ require (
github.com/prometheus/procfs v0.12.0 // indirect
go.opentelemetry.io/collector v0.97.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.97.0 // indirect
go.opentelemetry.io/collector/featuregate v1.4.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.46.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions processor/resourceprocessor/go.sum

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

0 comments on commit f29d215

Please sign in to comment.