-
Notifications
You must be signed in to change notification settings - Fork 805
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
[Wf-Diagnostics] introduce emitter interface in w/f diagnostics #6309
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// The MIT License (MIT) | ||
|
||
// Copyright (c) 2017-2020 Uber Technologies Inc. | ||
|
||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
package analytics | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/uber/cadence/.gen/go/indexer" | ||
"github.com/uber/cadence/common" | ||
"github.com/uber/cadence/common/messaging" | ||
) | ||
|
||
type Emitter DataEmitter | ||
|
||
type emitter struct { | ||
producer messaging.Producer | ||
} | ||
|
||
type EmitterParams struct { | ||
Producer messaging.Producer | ||
} | ||
|
||
func NewEmitter(p EmitterParams) DataEmitter { | ||
return &emitter{ | ||
producer: p.Producer, | ||
} | ||
} | ||
|
||
func (et *emitter) EmitUsageData(ctx context.Context, data WfDiagnosticsUsageData) error { | ||
msg := make(map[string]interface{}) | ||
msg[Domain] = data.Domain | ||
msg[WorkflowID] = data.WorkflowID | ||
msg[RunID] = data.RunID | ||
msg[Identity] = data.Identity | ||
msg[SatisfactionFeedback] = data.SatisfactionFeedback | ||
msg[IssueType] = data.IssueType | ||
msg[DiagnosticsWfID] = data.DiagnosticsWorkflowID | ||
msg[DiagnosticsWfRunID] = data.DiagnosticsRunID | ||
msg[Environment] = data.Environment | ||
msg[DiagnosticsStartTime] = data.DiagnosticsStartTime | ||
msg[DiagnosticsEndTime] = data.DiagnosticsEndTime | ||
|
||
serializedMsg, err := json.Marshal(msg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
pinotMsg := &indexer.PinotMessage{ | ||
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. shouldn't this layer be visibility-store agnostic? |
||
WorkflowID: common.StringPtr(data.DiagnosticsWorkflowID), | ||
Payload: serializedMsg, | ||
} | ||
return et.producer.Publish(ctx, pinotMsg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// The MIT License (MIT) | ||
|
||
// Copyright (c) 2017-2020 Uber Technologies Inc. | ||
|
||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
package analytics | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/uber/cadence/.gen/go/indexer" | ||
"github.com/uber/cadence/common/mocks" | ||
) | ||
|
||
func Test__EmitUsageData(t *testing.T) { | ||
|
||
testdata := WfDiagnosticsUsageData{ | ||
Domain: "test-domain", | ||
WorkflowID: "wid", | ||
RunID: "rid", | ||
Identity: "test@uber.com", | ||
IssueType: "timeouts", | ||
DiagnosticsWorkflowID: "diagnostics-wid", | ||
DiagnosticsRunID: "diagnostics-rid", | ||
Environment: "test-env", | ||
DiagnosticsStartTime: time.Now(), | ||
DiagnosticsEndTime: time.Now().Add(1 * time.Minute), | ||
SatisfactionFeedback: false, | ||
} | ||
mockErr := errors.New("mockErr") | ||
tests := map[string]struct { | ||
data WfDiagnosticsUsageData | ||
producerMockAffordance func(mockProducer *mocks.KafkaProducer) | ||
expectedError error | ||
}{ | ||
"Case1: normal case": { | ||
data: testdata, | ||
producerMockAffordance: func(mockProducer *mocks.KafkaProducer) { | ||
mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { | ||
require.Equal(t, testdata.DiagnosticsWorkflowID, input.GetWorkflowID()) | ||
return true | ||
})).Return(nil).Once() | ||
}, | ||
expectedError: nil, | ||
}, | ||
"Case1: error case": { | ||
data: testdata, | ||
producerMockAffordance: func(mockProducer *mocks.KafkaProducer) { | ||
mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { | ||
require.Equal(t, testdata.DiagnosticsWorkflowID, input.GetWorkflowID()) | ||
return true | ||
})).Return(mockErr).Once() | ||
}, | ||
expectedError: mockErr, | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
mockProducer := &mocks.KafkaProducer{} | ||
emitter := NewEmitter(EmitterParams{ | ||
Producer: mockProducer, | ||
}) | ||
test.producerMockAffordance(mockProducer) | ||
|
||
err := emitter.EmitUsageData(context.Background(), test.data) | ||
if test.expectedError != nil { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// The MIT License (MIT) | ||
|
||
// Copyright (c) 2017-2020 Uber Technologies Inc. | ||
|
||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
package analytics | ||
|
||
import ( | ||
"context" | ||
"time" | ||
) | ||
|
||
type WfDiagnosticsUsageData struct { | ||
Domain string | ||
WorkflowID string | ||
RunID string | ||
Identity string | ||
IssueType string | ||
DiagnosticsWorkflowID string | ||
DiagnosticsRunID string | ||
Environment string | ||
DiagnosticsStartTime time.Time | ||
DiagnosticsEndTime time.Time | ||
SatisfactionFeedback bool | ||
} | ||
|
||
// DataEmitter is the interface to emit workflow diagnostics data | ||
type DataEmitter interface { | ||
EmitUsageData(context.Context, WfDiagnosticsUsageData) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// The MIT License (MIT) | ||
|
||
// Copyright (c) 2017-2020 Uber Technologies Inc. | ||
|
||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
package analytics | ||
|
||
const ( | ||
Domain = "domain" | ||
WorkflowID = "workflowID" | ||
RunID = "runID" | ||
Identity = "identity" | ||
IssueType = "issue_type" | ||
DiagnosticsWfID = "diagnostics_workflowID" | ||
DiagnosticsWfRunID = "diagnostics_workflow_runID" | ||
SatisfactionFeedback = "satisfaction_feedback" | ||
Environment = "environment" | ||
DiagnosticsStartTime = "diagnostics_start_time" | ||
DiagnosticsEndTime = "diagnostics_end_time" | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why not just serialize
WfDiagnosticsUsageData
? It that to have some compatibility?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.
am following whats done in visibility. will double check with Neil too