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 frontend API handler and use generated code to emit metrics #5639

Merged
merged 1 commit into from
Feb 1, 2024

Conversation

Shaddoll
Copy link
Member

What changed?

  • Create a template to generate wrapper code of frontend API handler to emit metrics and logs on error
  • Refactor frontend API handler code

Why?
Tidy the messy code and make it maintainable

How did you test it?
unit tests

Potential risks

Release notes

Documentation Changes

@Shaddoll Shaddoll force-pushed the metered branch 2 times, most recently from e394dea to 11e23e1 Compare January 31, 2024 02:53
@coveralls
Copy link

coveralls commented Jan 31, 2024

Pull Request Test Coverage Report for Build 018d5dcb-1dcd-4c0d-b966-8acfb4c243d2

  • -401 of 635 (36.85%) changed or added relevant lines in 5 files are covered.
  • 84 unchanged lines in 6 files lost coverage.
  • Overall coverage increased (+0.05%) to 62.716%

Changes Missing Coverage Covered Lines Changed/Added Lines %
common/types/shared.go 0 5 0.0%
service/frontend/wrappers/metered/metered.go 169 250 67.6%
service/frontend/api/handler.go 61 376 16.22%
Files with Coverage Reduction New Missed Lines %
common/task/weighted_round_robin_task_scheduler.go 2 89.05%
service/history/task/transfer_active_task_executor.go 2 72.22%
service/history/task/transfer_standby_task_executor.go 2 87.42%
service/history/execution/mutable_state_task_refresher.go 7 62.34%
service/history/task/task_util.go 20 70.57%
service/frontend/api/handler.go 51 61.25%
Totals Coverage Status
Change from base Build 018d5cc7-1e74-4d61-a6e6-c60bbefb60ae: 0.05%
Covered Lines: 92224
Relevant Lines: 147050

💛 - Coveralls

Copy link
Contributor

@3vilhamster 3vilhamster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall - looks good and separating logic from metering/profiling makes it easier to follow the code.

@@ -228,17 +226,12 @@ func (wh *WorkflowHandler) Health(ctx context.Context) (*types.HealthStatus, err
// acts as a sandbox and provides isolation for all resources within the domain. All resources belongs to exactly one
// domain.
func (wh *WorkflowHandler) RegisterDomain(ctx context.Context, registerRequest *types.RegisterDomainRequest) (retError error) {
defer func() { log.CapturePanic(recover(), wh.GetLogger(), &retError) }()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a global panic handler somewhere? I think handling panic is not part of metering.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we don't. we can create a separate one later if we need that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: Panics in YARPC handlers are automatically caught and returned/logged as an error. This ensures that your process continues to run.

As of YARPC v1.43, YARPC now includes a metrics counter for panics.

So we can delete this completely.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's good to know

}

func (h *apiHandler) CountWorkflowExecutions(ctx context.Context, cp1 *types.CountWorkflowExecutionsRequest) (cp2 *types.CountWorkflowExecutionsResponse, err error) {
defer func() { log.CapturePanic(recover(), h.logger, &err) }()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks much better

tags := []tag.Tag{tag.WorkflowHandlerName("{{$method.Name}}")}
{{- $scope := printf "metrics.Frontend%sScope" $method.Name}}
{{- $domainMetricTag := "metrics.DomainUnknownTag()"}}
{{- if not (has $method.Name $nonDomainSpecificAPIs) }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a problem with this PR, but the fact that this there are ... kind of groupings and yet it's annoyingly hard to match them out makes me feel like we should maybe separate them out more at a struct / interface level in the future.

this is fine, but I worry that in future templating like this will get messy beyond the pont of being readable

Copy link
Member

@davidporter-id-au davidporter-id-au left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Significantly tidier, nice!

@Shaddoll Shaddoll merged commit efa13df into cadence-workflow:master Feb 1, 2024
16 checks passed
@Shaddoll Shaddoll deleted the metered branch February 1, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants