Skip to content

Conversation

vanhtuan0409
Copy link
Contributor

What changed?

Adding sql connection pool metrics from stdlib Stats

Why?

Expose more metrics for config fine tuning

How did you test it?

  • built
  • run locally and tested manually
  • covered by existing tests
  • added new unit test(s)
  • added new functional test(s)

@vanhtuan0409 vanhtuan0409 requested a review from a team as a code owner July 21, 2025 09:14
@CLAassistant
Copy link

CLAassistant commented Jul 21, 2025

CLA assistant check
All committers have signed the CLA.

@vanhtuan0409 vanhtuan0409 changed the title feat: adding sql connection pool metrics Adding sql connection pool metrics Jul 21, 2025
Copy link
Member

@bergundy bergundy left a comment

Choose a reason for hiding this comment

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

Apologies for the late review.

@bergundy bergundy changed the title Adding sql connection pool metrics Add sql connection pool metrics Sep 2, 2025
@bergundy bergundy enabled auto-merge (squash) September 4, 2025 22:53
auto-merge was automatically disabled September 5, 2025 04:23

Head branch was pushed to by a user without write access

@vanhtuan0409
Copy link
Contributor Author

vanhtuan0409 commented Sep 5, 2025

added concurrency guard in b9a7e9d

can you check again @bergundy

Comment on lines 19 to 20
started int32
stopped int32
Copy link
Member

Choose a reason for hiding this comment

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

Can use atomic bools here: https://pkg.go.dev/sync/atomic#Bool

Copy link
Member

Choose a reason for hiding this comment

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

But also wondering why this would be started multiple times since it's only instantiated in the handle constructor and immediately started there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I switched it to atomic.Bool in 921be96

Yeah, Start will probably only be called once, but Stop might be called multiple times, which I'm not sure about. Just keep it symmetric with the stop.

Before the guard check, the Go race detector complains about a race condition in WaitGroup. I'm adding these to resolve the race condition

Comment on lines 57 to 59
if atomic.LoadInt32(&r.stopped) == 1 {
return
}
Copy link
Member

Choose a reason for hiding this comment

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

A but redundant IMHO but no objection to keep this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure enough. I'm keeping this at the moment

Copy link
Member

@bergundy bergundy left a comment

Choose a reason for hiding this comment

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

I've already approved this, at this point it's nitpicking. Feel free to address the last couple of comments if you feel like it. Otherwise, I can merge as is.

Comment on lines +33 to +34
reporter.started.Store(false)
reporter.stopped.Store(false)
Copy link
Member

Choose a reason for hiding this comment

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

No need, the zero value is false.

Comment on lines +42 to +44
if !r.started.CompareAndSwap(false, true) {
return
}
Copy link
Member

Choose a reason for hiding this comment

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

Still don't feel like we need this but 🤷

Comment on lines +45 to +46
r.wg.Add(1)
go r.run()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
r.wg.Add(1)
go r.run()
r.wg.Go(r.run)

}

func (r *DBMetricsReporter) run() {
defer r.wg.Done()
Copy link
Member

Choose a reason for hiding this comment

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

No need if you use wg.Go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh nice. I just know about this method. Unfortunately, it is only available with go 1.25. Temporal is using go 1.24 instead

Copy link
Member

Choose a reason for hiding this comment

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

That's not true anymore

go 1.25.0

@vanhtuan0409
Copy link
Contributor Author

the CI is failing. Do I need to rebase or checking anything @bergundy . Look like some docker service is missing

@bergundy
Copy link
Member

bergundy commented Sep 8, 2025

I merged main into the PR branch, lets see if that fixes CI.

@vanhtuan0409
Copy link
Contributor Author

All good. It is great working with you

@bergundy
Copy link
Member

bergundy commented Sep 9, 2025

I'm merging, would have liked some of the small comments to have been addressed but there's nothing critical blocking this right now. Thanks for the contribution.

@bergundy bergundy merged commit 0eb7f21 into temporalio:main Sep 9, 2025
58 checks passed
@vanhtuan0409 vanhtuan0409 deleted the sql-conn-metrics branch September 9, 2025 00:12

func (r *DBMetricsReporter) report() {
db := r.handle.db.Load()
if db == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

@bergundy should stats go to zero if this occurs?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm... this is just an edge case. I would say it's undefined. Most of the time the gauge will stay at the last value for the host.

@erka erka mentioned this pull request Sep 10, 2025
5 tasks
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.

4 participants