Skip to content
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

refactor: reduce the error report sample events #5371

Merged
merged 16 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion enterprise/reporting/label_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewLabelSet(metric types.PUReportedMetric, bucket int64) LabelSet {
}

func (labelSet LabelSet) generateHash() string {
data := labelSet.WorkspaceID + labelSet.SourceDefinitionID + labelSet.SourceCategory + labelSet.SourceID + labelSet.DestinationDefinitionID + labelSet.DestinationID + labelSet.SourceTaskRunID + labelSet.SourceJobID + labelSet.SourceJobRunID + labelSet.TransformationID + labelSet.TransformationVersionID + labelSet.TrackingPlanID + strconv.Itoa(labelSet.TrackingPlanVersion) + labelSet.InPU + labelSet.PU + labelSet.Status + strconv.FormatBool(labelSet.TerminalState) + strconv.FormatBool(labelSet.InitialState) + strconv.Itoa(labelSet.StatusCode) + labelSet.EventName + labelSet.EventType + labelSet.ErrorType + strconv.FormatInt(labelSet.Bucket, 10)
data := labelSet.WorkspaceID + labelSet.SourceDefinitionID + labelSet.SourceCategory + labelSet.SourceID + labelSet.DestinationDefinitionID + labelSet.DestinationID + labelSet.SourceTaskRunID + labelSet.SourceJobID + labelSet.SourceJobRunID + labelSet.TransformationID + labelSet.TransformationVersionID + labelSet.TrackingPlanID + strconv.Itoa(labelSet.TrackingPlanVersion) + labelSet.InPU + labelSet.PU + labelSet.Status + strconv.FormatBool(labelSet.TerminalState) + strconv.FormatBool(labelSet.InitialState) + strconv.Itoa(labelSet.StatusCode) + labelSet.EventName + labelSet.EventType + labelSet.ErrorType + strconv.FormatInt(labelSet.Bucket, 10) + labelSet.ErrorCode + labelSet.ErrorMessage
hash := murmur3.Sum64([]byte(data))
return hex.EncodeToString([]byte(strconv.FormatUint(hash, 16)))
}
62 changes: 45 additions & 17 deletions enterprise/reporting/label_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"github.com/rudderlabs/rudder-server/utils/types"
)

func createMetricObject(eventName string) types.PUReportedMetric {
return types.PUReportedMetric{
const someEventName = "some-event-name"

func createMetricObject(eventName string, withError bool) types.PUReportedMetric {
metric := types.PUReportedMetric{
ConnectionDetails: types.ConnectionDetails{
SourceID: "some-source-id",
DestinationID: "some-destination-id",
Expand All @@ -28,35 +30,61 @@ func createMetricObject(eventName string) types.PUReportedMetric {
EventType: "some-event-type",
},
}
if withError {
metric.StatusDetail.ErrorDetails = types.ErrorDetails{
Code: "some-error-code",
Message: "some-error-message",
}
}
return metric
}

func TestNewLabelSet(t *testing.T) {
t.Run("should create the correct LabelSet from types.PUReportedMetric", func(t *testing.T) {
inputMetric := createMetricObject("some-event-name")
inputMetric := createMetricObject(someEventName, false)
bucket := int64(28889820)
labelSet := NewLabelSet(inputMetric, bucket)

assert.Equal(t, "some-source-id", labelSet.SourceID)
assert.Equal(t, "some-event-name", labelSet.EventName) // Default value
assert.Equal(t, someEventName, labelSet.EventName) // Default value
})
}

t.Run("should create the correct LabelSet with custom EventName", func(t *testing.T) {
inputMetric := createMetricObject("custom-event-name")
func TestGenerateHash(t *testing.T) {
t.Run("same hash for same LabelSet for metrics", func(t *testing.T) {
inputMetric1 := createMetricObject(someEventName, false)
bucket := int64(28889820)
labelSet := NewLabelSet(inputMetric, bucket)
labelSet1 := NewLabelSet(inputMetric1, bucket)

assert.Equal(t, "some-source-id", labelSet.SourceID)
assert.Equal(t, "custom-event-name", labelSet.EventName) // Custom event name
inputMetric2 := createMetricObject(someEventName, false)
labelSet2 := NewLabelSet(inputMetric2, bucket)

hash1 := labelSet1.generateHash()
hash2 := labelSet2.generateHash()

assert.Equal(t, hash1, hash2)
})
}

func TestGenerateHash(t *testing.T) {
t.Run("same hash for same LabelSet", func(t *testing.T) {
inputMetric1 := createMetricObject("some-event-name")
t.Run("different hash for different LabelSet for metrics", func(t *testing.T) {
inputMetric1 := createMetricObject("some-event-name-1", false)
bucket := int64(28889820)
labelSet1 := NewLabelSet(inputMetric1, bucket)

inputMetric2 := createMetricObject("some-event-name-2", false)
labelSet2 := NewLabelSet(inputMetric2, bucket)

hash1 := labelSet1.generateHash()
hash2 := labelSet2.generateHash()

assert.NotEqual(t, hash1, hash2)
})

t.Run("same hash for same LabelSet for errors", func(t *testing.T) {
inputMetric1 := createMetricObject(someEventName, true)
bucket := int64(28889820)
labelSet1 := NewLabelSet(inputMetric1, bucket)

inputMetric2 := createMetricObject("some-event-name")
inputMetric2 := createMetricObject(someEventName, true)
labelSet2 := NewLabelSet(inputMetric2, bucket)

hash1 := labelSet1.generateHash()
Expand All @@ -65,12 +93,12 @@ func TestGenerateHash(t *testing.T) {
assert.Equal(t, hash1, hash2)
})

t.Run("different hash for different LabelSet", func(t *testing.T) {
inputMetric1 := createMetricObject("some-event-name-1")
t.Run("different hash for different LabelSet for errors", func(t *testing.T) {
inputMetric1 := createMetricObject("some-event-name-1", true)
bucket := int64(28889820)
labelSet1 := NewLabelSet(inputMetric1, bucket)

inputMetric2 := createMetricObject("some-event-name-2")
inputMetric2 := createMetricObject("some-event-name-2", true)
koladilip marked this conversation as resolved.
Show resolved Hide resolved
labelSet2 := NewLabelSet(inputMetric2, bucket)

hash1 := labelSet1.generateHash()
Expand Down
Loading