Add ETag caching for the pod logs json API
What does this MR do?
Follow-up from !17881 (comment 233082402):
Add ETag caching for the Pod Logs JSON API.
This API uses reactive caching, which means that the frontend needs to poll the API until a non 202 response is returned. Using ETag caching here should reduce the load caused by the polling.
The API uses query parameters (pod_name
and container_name
), which does not work with ETag caching. Therefore, this MR also changes the API to use path parameters instead of query parameters.
This MR also changes the frontend to call the API with path parameters instead of query parameters.
In summary, the changes in this MR are:
- Change pod logs JSON API to use path parameters instead of query parameters. backend
- Change the route.
- Separate out the HTML and JSON format responses into 2 APIs since they are quite different now.
- Use ETag caching with pod logs JSON API. backend
- Add entry to router in Gitlab::EtagCaching::Router.
- Pass
environment.id
as parameter toread_pod_logs
method inee/app/models/ee/clusters/platforms/kubernetes.rb
.environment.id
is required in order to invalidate the ETag cache. - Invalidate ETag cache using the
reactive_cache_updated
hook that theReactiveCaching
concern provides. Thereactive_cache_updated
method will be called whenever the value in the reactive cache is generated, updated, or deleted.
- Change frontend to call pod logs JSON API with path parameters. frontend
- Add new entry and method to
ee/app/assets/javascripts/api.js
. - Pass
project.full_path
andenvironment.id
to frontend viaenvironments_helper.rb
. These two values are required forapi.js
to generate the API request path. - Change
ee/app/assets/javascripts/kubernetes_logs.js
to call API defined inapi.js
.
- Add new entry and method to
- Modify the backoff timeout (for polling pod logs API) in
ee/app/assets/javascripts/kubernetes_logs.js
to 120 seconds. It was previously using the default timeout of 60 seconds. frontend
Screenshots
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation created/updated or follow-up review issue created -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team