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 user agent to HTTP client #5724

Merged

Conversation

leonardehrenfried
Copy link
Member

@leonardehrenfried leonardehrenfried commented Mar 4, 2024

Summary

On one of my deployments we also use Entur's Lamassu with ~70 GBFS feeds. OTP's regular GBFS downloading was
leading another developer looking after Lamassu to think that a load test was underway. 😳

For this reason I'm setting a user agent identifying HTTP calls that originate from OTP.

cc @derhuerst @hbruch

@leonardehrenfried
Copy link
Member Author

@t2gran The architecture test fails because of a dependency on org.opentripplanner.model.projectinfo. May I allow this dependency?

@vpaturet vpaturet self-requested a review March 5, 2024 09:10
@leonardehrenfried leonardehrenfried changed the title Add user agent to OTP HTTP client Add user agent to HTTP client Mar 5, 2024
@leonardehrenfried
Copy link
Member Author

leonardehrenfried commented Mar 5, 2024

I just checked and the current user agent is "Apache-HttpClient/5.3.1 (Java/21.0.2)".

With almost all updaters you can configure the HTTP headers and if you set User-Agent then your customised version will be used rather than the default.

Copy link

codecov bot commented Mar 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.76%. Comparing base (6fc4f60) to head (6c956b8).

Additional details and impacted files
@@            Coverage Diff             @@
##             dev-2.x    #5724   +/-   ##
==========================================
  Coverage      67.76%   67.76%           
  Complexity     16471    16471           
==========================================
  Files           1901     1901           
  Lines          72113    72114    +1     
  Branches        7430     7430           
==========================================
+ Hits           48868    48869    +1     
  Misses         20734    20734           
  Partials        2511     2511           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@optionsome
Copy link
Member

Btw is it possible to define custom user agent through updater configuration after this?

@leonardehrenfried
Copy link
Member Author

leonardehrenfried commented Mar 6, 2024

Yes, you can set the User-Agent header and it overrides the one I'm setting in this PR. That also works before this PR.

@derhuerst
Copy link
Contributor

derhuerst commented Mar 6, 2024

I strongly suggest nudging users to define their own User-Agent(s) – as this is a best practice when querying (potentially third-party) APIs automatically –, e.g. by adding an example configuration to the docs or even printing a warning if no custom User-Agent is configured.

@t2gran
Copy link
Member

t2gran commented Mar 8, 2024

@derhuerst I agree that it is a is a best practice for a C2B service, but in this case it is a B2B call, OTP call the RT-Services. In most cases just using "OpenTripPlanner" should be sufficient. I would also recommend having an aggregator service between OTP and the RT-Services - especially if there are many OTP instances. The aggregator should maintain a clean consistent set of updates and remove old updates. It minimize the calls to the RT-Services and keep the latency between the aggregator and OTP down, while removing some of the load from the OTP instances. The aggregator and OTP should be in the same data senter or same cluster.

@t2gran
Copy link
Member

t2gran commented Mar 8, 2024

The architecture test fails because of a dependency on org.opentripplanner.model.projectinfo. May I allow this dependency?

For the record, this was discussed in the dev meeting. Dependencies from the framework code to the domain model is not allowed. The solution in this case was to drop the version number from the token. Another alternative is to pass inn the client-name as parameter when the HTTP Client is created.

@leonardehrenfried leonardehrenfried merged commit 51a381e into opentripplanner:dev-2.x Mar 12, 2024
5 checks passed
@t2gran t2gran added this to the 2.5 (next release) milestone Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants