Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
ketsiambaku committed Aug 29, 2024
1 parent d7346b6 commit 3d2e3e3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 20 deletions.
10 changes: 0 additions & 10 deletions debug/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,3 @@ type (
// Deprecated: in development and very likely to change
Activities = internal.Activities
)

func (a Activities) GroupByActivityType() Activities {
// implement me... maybe here or in monorepo ??
return nil
}

func (a Activities) GroupByWorkflowID() Activities {
// implement me... maybe ??
return nil
}
84 changes: 74 additions & 10 deletions internal/common/debug/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
package debug

import (
"encoding/json"
"fmt"
"sync"

"go.uber.org/atomic"
"sync"
)

type (
Expand Down Expand Up @@ -105,24 +105,88 @@ func Example() {
pollerTracker = &pollerTrackerImpl{}

// Initially, poller count should be 0
fmt.Println(fmt.Sprintf("stats: %d", pollerTracker.Stats()))
fmt.Println(fmt.Sprintf("poller stats: %d", pollerTracker.Stats()))

// Start a poller and verify that the count increments
stopper1 := pollerTracker.Start()
fmt.Println(fmt.Sprintf("stats: %d", pollerTracker.Stats()))
fmt.Println(fmt.Sprintf("poller stats: %d", pollerTracker.Stats()))

// Start another poller and verify that the count increments again
stopper2 := pollerTracker.Start()
fmt.Println(fmt.Sprintf("stats: %d", pollerTracker.Stats()))
fmt.Println(fmt.Sprintf("poller stats: %d", pollerTracker.Stats()))

// Stop the pollers and verify the counter
stopper1.Stop()
stopper2.Stop()
fmt.Println(fmt.Sprintf("stats: %d", pollerTracker.Stats()))
fmt.Println(fmt.Sprintf("poller stats: %d", pollerTracker.Stats()))

var activityTracker ActivityTracker
activityTracker = &activityTrackerImpl{m: make(map[ActivityInfo]int64)}

info1 := ActivityInfo{
WorkflowID: "id1",
RunID: "rid1",
TaskList: "task-list",
ActivityType: "activity",
}

info2 := ActivityInfo{
WorkflowID: "id2",
RunID: "rid2",
TaskList: "task-list",
ActivityType: "activity",
}

stopper1 = activityTracker.Start(info1)
stopper2 = activityTracker.Start(info2)
jsonActivities, _ := json.MarshalIndent(activityTracker.Stats(), "", " ")
fmt.Println(string(jsonActivities))

stopper1.Stop()
stopper1.Stop()
jsonActivities, _ = json.MarshalIndent(activityTracker.Stats(), "", " ")

fmt.Println(string(jsonActivities))
stopper2.Stop()

jsonActivities, _ = json.MarshalIndent(activityTracker.Stats(), "", " ")
fmt.Println(string(jsonActivities))

// Output:
// stats: 0
// stats: 1
// stats: 2
// stats: 0
// poller stats: 0
// poller stats: 1
// poller stats: 2
// poller stats: 0
// [
// {
// "Info": {
// "WorkflowID": "id1",
// "RunID": "rid1",
// "TaskList": "task-list",
// "ActivityType": "activity"
// },
// "Count": 1
// },
// {
// "Info": {
// "WorkflowID": "id2",
// "RunID": "rid2",
// "TaskList": "task-list",
// "ActivityType": "activity"
// },
// "Count": 1
// }
// ]
// [
// {
// "Info": {
// "WorkflowID": "id2",
// "RunID": "rid2",
// "TaskList": "task-list",
// "ActivityType": "activity"
// },
// "Count": 1
// }
// ]
// null
}
3 changes: 3 additions & 0 deletions internal/common/debug/workerstats_noop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ import (

func TestWorkerStats(t *testing.T) {
pollerTracker := NewNoopPollerTracker()
activityTracker := NewNoopActivityTracker()
assert.NotNil(t, pollerTracker)
assert.NotNil(t, pollerTracker.Start())
assert.Equal(t, int32(0), pollerTracker.Stats())
assert.NotPanics(t, pollerTracker.Start().Stop)
assert.NotNil(t, activityTracker.Start(ActivityInfo{}))
assert.Nil(t, activityTracker.Stats())
}

0 comments on commit 3d2e3e3

Please sign in to comment.