-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix-peer-notifications2
- Loading branch information
Showing
4 changed files
with
255 additions
and
0 deletions.
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{ | ||
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" | ||
) |