Skip to content

Store state in share link url #86

@junosuarez

Description

@junosuarez

Feature request

As an administrator, I want to enable link sharing without configuring a backing store.

eg, Grafana's Explore page encodes relevant state like:

https://example.com/grafana/explore?orgId=1&left=%7B%22datasource%22:%228M8oDGJVz%22,%22queries%22:%5B%7B%22refId%22:%22A%22,%22datasource%22:%7B%22type%22:%22prometheus%22,%22uid%22:%228M8oDGJVz%22%7D,%22editorMode%22:%22builder%22,%22expr%22:%22go_build_info%22,%22legendFormat%22:%22__auto%22,%22range%22:true,%22instant%22:true%7D%5D,%22range%22:%7B%22from%22:%22now-1h%22,%22to%22:%22now%22%7D%7D

Benefit

Users could simply copy/paste the URL from the browser, without using the special share link UI.
It would also make Promlens operationally simpler, without requiring additional external resources.

Background

Currently, Promlens requires a storage provider (eg postgres or sqlite) to enable the share link functionality.

Looking at https://github.com/prometheus/promlens/blob/0e62d284ab9b15ef9ba380adb795bda5d8922621/pkg/sharer/sharer.go , this happens by approximately like:

  1. user clicks "share link" button in client UI
  2. client sends JSON of page state to server
  3. server takes JSON string and generates a hash to use as the key and stores the JSON string at key
  4. server returns key to client
  5. client shows link in UI e.g. https://promlens-instance/?l=<key>

If the state were serialized in the link itself, the flow would be simplied:

  1. user clicks "share link" button in client UI
  2. client serializes page state (eg, base64 encoded json) and appends to URL as query fragment, eg https://promlens-instance/#<state>
  3. client shows UI

or further:

  1. as page state changes, client serializes page state into location hash with History.replaceState
  2. at any point, user can copy the URL from the browser address bar

The above examples are a sketch, I'm flexible to other implementation approaches.

Is this in line with the direction for this project? I'm happy to help implement and test or discuss further.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions