Skip to content

Add ETag caching for the pod logs json API

Reuben Pereira requested to merge pod-logs-add-etag-caching into master

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:

  1. Change pod logs JSON API to use path parameters instead of query parameters. backend
    1. Change the route.
    2. Separate out the HTML and JSON format responses into 2 APIs since they are quite different now.
  2. Use ETag caching with pod logs JSON API. backend
    1. Add entry to router in Gitlab::EtagCaching::Router.
    2. Pass environment.id as parameter to read_pod_logs method in ee/app/models/ee/clusters/platforms/kubernetes.rb. environment.id is required in order to invalidate the ETag cache.
    3. Invalidate ETag cache using the reactive_cache_updated hook that the ReactiveCaching concern provides. The reactive_cache_updated method will be called whenever the value in the reactive cache is generated, updated, or deleted.
  3. Change frontend to call pod logs JSON API with path parameters. frontend
    1. Add new entry and method to ee/app/assets/javascripts/api.js.
    2. Pass project.full_path and environment.id to frontend via environments_helper.rb. These two values are required for api.js to generate the API request path.
    3. Change ee/app/assets/javascripts/kubernetes_logs.js to call API defined in api.js.
  4. 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

Availability and Testing

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
Edited by 🤖 GitLab Bot 🤖

Merge request reports