Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Access JFR data faster with Cryostat 2.1's new download APIs

 

May 25, 2022
Hareet Dhillon
Related topics:
ContainersJavaKubernetes
Related products:
Red Hat build of OpenJDK

Share:

    Cryostat is a tool for managing JDK Flight Recorder data on Kubernetes. This article explains how new download APIs based on JSON Web Tokens (JWTs) help facilitate a more responsive and efficient download workflow in the Cryostat 2.1 web client.

    The Cryostat web client download workflow

    Previously, the web client download flow for resources such as recordings, reports, and templates consisted of the application firing an HTTP GET request with the appropriate authorization header(s) to the back-end, downloading the returned file into browser memory, creating a local object URL for the blob, and then assigning the URL to an anchor element prompting user response. The file size determined the download speed and when the "Save File" prompt would appear. Once this process was completed, the user would be prompted to save the file to disk or cancel the download even though the file had already been transferred to the user’s machine.

    Cryostat 2.1 improves the download flow by using the HTML 5 download attribute available in most browsers. Specifically, an anchor element is created with the href attribute set to a URL for the resource provided by the back-end, and the download attribute is set to the file name. When the anchor is clicked,  the “Save File” prompt appears (see Figure 1).

    The Recordings view for a sample application in the Cryostat web client. A recording download has been requested causing the "Save File" prompt to show.
    Figure 1: The "Save File" prompt allows users to decide whether they want to save the recording file to disk or not.

    If the user clicks “Save File,” the file downloads directly to disk. If the user clicks "Cancel," the file will not be downloaded. Another benefit is that the time to display the “Save File” dialog is no longer dependent on the file size because nothing is being downloaded into the browser memory.

    However, a limitation of the href attribute is that it is not possible to provide headers with the URL without authorization to retrieve the resource. This is where JSON Web Tokens come in.

    How JSON Web Tokens improve download workflow

    JWTs are credentials that ensure the user sending the server request is the same user that was authenticated (i.e., logged in) previously in the session and also has access to the requested resource. They consist of JSON payloads containing authorization metadata. 

    Cryostat 2.1 has implemented new API handlers to help facilitate JWT downloads. When a user downloads a file through the web client, a POST request containing the required authorization headers and a multipart form attribute identifying the requested resource is sent to the /api/v2.1/auth/token endpoint. The API handler encodes the information into a JWT token, symmetrically encrypts it, and returns a resource URL associated with the token. This is the URL to which the aforementioned href attribute is set. When the anchor element is clicked, the resulting GET request for the file resource will be authorized using the JWT token, solving the problem of not being able to provide any headers with the href attribute.

    Any JWT token-associated GET requests are handled by new version 2.1 API handlers specifically designed for this purpose. The web client extensively uses these because of the improved browser-related performance. However, other API clients, such as user-created automated workflows, can continue using the original version 1 download APIs because they do not require generating JWT tokens which are functionally identical to the new version 2.1 handlers.

    Figure 2 shows the main Cryostat container logs when a recording download request from the web client is received.

    The main Cryostat container logs with the HTTP requests comprising the web client recording download workflow highlighted. There is a POST request to generate the JWT token and a subsequent GET request using the token-associated URL returned by the POST request to retrieve the actual recording file.
    Figure 2: The recording download request in Figure 1 results in the two HTTP requests shown here.

    Conclusion

    New JWT-based download APIs allow the Cryostat web client to provide an improved resource download workflow for users. For more information on Cryostat such as guides and contact information, visit us at cryostat.io.

    Find more Cryostat tutorials on Red Hat Developer:

    • Introduction to Cryostat: JDK Flight Recorder for containers
    • How to build automated JFR rules with Cryostat 2.1's new UI
    • Tutorial: Configuring Java applications to use Cryostat
    Last updated: September 26, 2024

    Related Posts

    • Announcing Cryostat 2.0: JDK Flight Recorder for containers

    • Collect JDK Flight Recorder events at runtime with JMC Agent

    • Custom JFR event templates with Cryostat 2.0

    Recent Posts

    • More Essential AI tutorials for Node.js Developers

    • How to run a fraud detection AI model on RHEL CVMs

    • How we use software provenance at Red Hat

    • Alternatives to creating bootc images from scratch

    • How to update OpenStack Services on OpenShift

    What’s up next?

    Book cover for Modernizing Enterprise Java

    Modernizing Enterprise Java is a practical guide that examines long-established Java-based models and shows you how to bring these monolithic applications successfully into a modern, cloud-native model with Kubernetes.

    Get the e-book
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue