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

Update to metrics sample #197

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion metrics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ go run metrics/worker/main.go
```
go run metrics/starter/main.go
```
4) Check metrics at http://localhost:9090/metrics (this is where the Prometheus agent scrapes it from).
4) Check metrics at http://localhost:9092/metrics
You can set up Prometheus scrape point config to use this url
4 changes: 3 additions & 1 deletion metrics/worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func main() {
// The client and worker are heavyweight objects that should be created once per process.
c, err := client.NewClient(client.Options{
MetricsHandler: sdktally.NewMetricsHandler(newPrometheusScope(prometheus.Configuration{
ListenAddress: "0.0.0.0:9090",
ListenAddress: "0.0.0.0:9092",
TimerType: "histogram",
})),
})
Expand Down Expand Up @@ -55,6 +55,8 @@ func newPrometheusScope(c prometheus.Configuration) tally.Scope {
Separator: prometheus.DefaultSeparator,
SanitizeOptions: &sanitizeOptions,
Prefix: "temporal_samples",
Tags: map[string]string{"my_key1": "my_value1",
"my_key2": "my_value2"},
}
scope, _ := tally.NewRootScope(scopeOpts, time.Second)

Expand Down
3 changes: 3 additions & 0 deletions metrics/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func Workflow(ctx workflow.Context) error {
logger := workflow.GetLogger(ctx)
logger.Info("Metrics workflow started.")

// increment custom counter
workflow.GetMetricsHandler(ctx).Counter("my_workflow_counter").Inc(1)

scheduledTimeNanos := workflow.Now(ctx).UnixNano()
_ = workflow.Sleep(ctx, 500*time.Millisecond)
err := workflow.ExecuteActivity(ctx, Activity, scheduledTimeNanos).Get(ctx, nil)
Expand Down