grafana / explore-profiles

Explore Profiles is a native Grafana application designed to integrate seamlessly with Pyroscope, the open-source continuous profiling platform, providing a smooth, query-less experience for browsing and analyzing profiling data.
GNU Affero General Public License v3.0
17 stars 1 forks source link

fix(Labels): Fix "Discarded by user" error in the UI #110

Closed grafakus closed 1 month ago

grafakus commented 1 month ago

✨ Description

Related issue(s): -

This PR fixes an error that can occur when changing the data source or clicking on the main refresh button in the UI:

image image

Additionally, this PR also fixes a potential issue with the query builder, which does not update its API client whenever the data source changes.

📖 Summary of the changes

The error comes from an unwanted interaction between the query builder and LabelsDataSource where the API request made by LabelsDataSource to fetch label names is cancelled by the query builder state machine. This happens because the both share the same instance of the LabelsRepository class, which in turn uses the same API client.

The scenario is the following:

Whenever the user changes the data source:

  1. GroupByVariable gets its options updated via LabelsDataSource
  2. In LabelsDataSource, LabelsRepository sets the API client corresponding to the new data source
  3. the query builder state machine receives new input parameters, which in turn, causes the machine to transition to its idle state
  4. when entering this state, all in-flight requests are cancelled (see QueryBuilder/domain/actions.ts)
  5. because the same API client is used by LabelsRepository, this throws an abort error that bubbles up to the "Group by" UI

The solution is to make sure distinct instances of the API client are created by the query builder and by LabelsDataSource.

See the diff tab for additional specific comments.

🧪 How to test?

github-actions[bot] commented 1 month ago

Unit test coverage

Lines Statements Branches Functions
Coverage: 11%
12.04% (464/3853) 9.35% (134/1432) 9.11% (107/1174)