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

Add Ability to pass own client in AsyncHttpClient so that it's state can be referenced #3859

Merged
merged 5 commits into from Nov 15, 2020

Conversation

harpresing
Copy link
Contributor

Currently there is no way to access org.asynchttpclient.DefaultAsyncHttpClient#getClientStat when we create a Resource[F, Client[F]] using org.http4s.client.asynchttpclient.AsyncHttpClient#resource.

This PR adds an additional apply method in AsyncHttpClient which lets the user pass in their own DefaultAsyncHttpClient so that they can have a handle on its state and use it for metrics etc.

def getTotalConnectionCount: F[Long] = F.delay(underlying.getTotalConnectionCount)
def getTotalActiveConnectionCount: F[Long] = F.delay(underlying.getTotalActiveConnectionCount)
def getTotalIdleConnectionCount: F[Long] = F.delay(underlying.getTotalIdleConnectionCount)
def getStatsPerHost: F[mutable.Map[String, HostStats]] =
Copy link
Member

Choose a reason for hiding this comment

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

Could we return an immutable map here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

override def remove(pred: java.util.function.Predicate[Cookie]): Boolean = false
override def clear(): Boolean = false
}

final case class AsyncHttpClientStats[F[_]: Sync](private val underlying: ClientStats)(implicit
Copy link
Member

Choose a reason for hiding this comment

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

I don't think I'd make this a case class. There is no meaningful equals, toString, etc, and it's not exactly a product type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, I've made it a simple class

override def remove(pred: java.util.function.Predicate[Cookie]): Boolean = false
override def clear(): Boolean = false
}

final case class AsyncHttpClientStats[F[_]: Sync](private val underlying: ClientStats)(implicit
Copy link
Member

Choose a reason for hiding this comment

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

I'd put this class in its own source file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to it's own file

@rossabaker rossabaker added the enhancement Feature requests and improvements label Nov 14, 2020
Copy link
Member

@rossabaker rossabaker left a comment

Choose a reason for hiding this comment

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

Test failure is unrelated. This looks great!

@harpresing
Copy link
Contributor Author

Thanks for reviewing it @rossabaker! I can't merge it though since I don't have write access to the repository 😅

@rossabaker
Copy link
Member

We usually aim for two reviewers, but sometimes our reviewers get busy. I'll go ahead and merge it, and aim to release it this week.

@rossabaker rossabaker merged commit ee00eb7 into http4s:series/0.21 Nov 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests and improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants