How Grafana Uses React to Power the World of Observability

Rate this content
Bookmark
Slides

Why does Grafana use React for its frontend?
How we leverage React’s features at Grafana
What are some pain points we have ran into with using React at Grafana
What are lessons learned from adopting React for the past 5+ years?

Nathan Marrs
Nathan Marrs
7 min
06 Jun, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Grafana uses React to power its open source platform, leveraging its vast ecosystem, improved performance, and community contributions. The choice of state management tool depends on the team's problem space. React Hooks have posed challenges but have also been a powerful tool for developers. The new Scenes library simplifies development and reduces the learning curve. Despite challenges, React remains a powerful tool for complex frontends, and Grafana will continue to use it.

Available in Español

1. Introduction to Grafana's Use of React

Short description:

Hi, I'm Nathan Mars, the tech lead at Grafana Labs. Grafana uses React to power its open source platform, providing benefits like a vast ecosystem, improved performance, and community contributions. However, React's state management has posed challenges, leading Grafana to use a mixture of Redux, RxJS, Props, and Context. The choice of state management tool depends on the team's problem space.

Hi, my name is Nathan Mars and I'm the tech lead of the data visualization squad at Grafana Labs. Today, I'm excited to share with you how Grafana leverages React to power its widely used open source platform that enables millions of users to visualize and analyze their data.

Let's begin with a story. Grafana didn't always use React. In fact, it first used Angular. In 2018, the team came up at a crossroads. Either migrate to Angular 2 from Angular 1 or consider other options. Ultimately, the team decided to switch over to React as the effort wasn't too different migrating to Angular 2 required and React was what talented people wanted to work with. With the decision made to switch to React, the immense migration commenced. This is another story entirely, and it's still ongoing.

Today, we use React to power the entire front end of Grafana from dashboards to explorer to alerting and much more. React has provided us with some significant benefits. Firstly, React's ecosystem is immense. It's almost at the same level of there's an app for that, but, instead, it's there's a third party library for that. Being able to tap into this ecosystem has allowed us to ship features faster and reduce the technical debt we own. For example, we wanted to build a new panel type called Canvas that allows for creating custom layouts and UIs. A third-party library called Movable helped us out immensely, getting us to beta state months earlier than we otherwise would have. React's performance is another benefit that has allowed us to scale. The built-in rendering optimizations, as well as class-based components should component update and hooks dependencies arrays, have made it easier for us to optimize our codes' performance and ultimately provide a great user experience.

Another benefit of using React is its ubiquity. As Grafana is open source, being based on the most popular frontend library has helped facilitate community contributions to Grafana. However, Grafana has also experienced some challenges with React, especially when it comes to state management. React has never claimed to be a framework, unlike Angular, so the question of how to manage a complex app state while using React has long been open-ended. Before context, there was Redux. Before Redux, there was the good old unidirectional passing of props. What has Grafana's approach been to this? Well, to use them all in a mixture. From Redux, RxJS, Props and Context, and more. As Grafana matures, it is yet to be seen if this approach is sustainable. In general, we feel that a team should use a state management tool that best fits their problem space. The ambiguity of which solution to use is a classic problem for versatile, open source libraries and platforms.

2. Grafana's Use of React and Challenges with Hooks

Short description:

Grafana supports a wide range of data sources and aims to provide flexibility in visualizing data. However, this can lead to confusion for users in finding the best solution. React Hooks have posed challenges, but they have also been a powerful tool for developers. Grafana is excited to announce the new Scenes library, which simplifies development and reduces the learning curve. Despite challenges, React remains a powerful tool for complex frontends, and Grafana will continue to use it.

Grafana itself has a BigTent philosophy, supporting as much of the observability ecosystem as possible. This provides our users with a huge amount of flexibility in visualizing their data, no matter what the source, be it from their Kubernetes cluster, Raspberry Pi, different cloud services, or even Google Sheets.

At the same time, though, this can lead to confusion from our end users in figuring out how to construct the best observability solution for themselves.

Another challenge we have faced with React is with the Hooks paradigm. Some at Grafana have expressed their frustration with Hooks as they introduce stale closures and require learning and mastering Hook rules. Functional components, as they are called, are rarely pure functions. Hooks also introduce a much stronger coupling with the React runtime than before. The name Hook indicates this. You are hooking into React internals. So you need to understand those internals. Hooks are far from being a functional abstraction, as you need to know the internal details of their implementation. This becomes even more apparent when you try to test one hook in isolation.

React has followed a functional programming paradigm. And some fear with the introduction of Hooks that it may be straying from that paradigm and entering into framework land. Although some at Grafana have expressed concerns with Hooks, it's important to note that they have been a powerful tool for our developers. As with any tool, there may be a learning curve, but once mastered, they can greatly enhance the development process. At Grafana, we recognize the importance of exploring and experimenting with new tools and methodologies to continually improve our development processes. We appreciate the benefits that Hooks have brought to our development workflow and continue to explore new ways to enhance our tools and processes.

With that being said, we are excited to announce our new approach to building our next-generation dashboard runtime library, Scenes. We have taken a different approach that simplifies the development process and reduces the learning curve for our developers. With Scenes, each component subscribes to state build with ArcGIS, renders markup, and pipes callbacks back to the state model. We have eliminated the need for complicated concepts such as useEffects and useCallbacks. The state model takes care of any necessary mount effects, making the development process more intuitive and efficient. We are confident that our new library will be a game changer for our developers and we believe that this simplified approach will lead to a more positive development experience. Although the library is still in its early stages of development, we are excited to see how it will continue to evolve and improve the way we build our dashboards.

Despite our challenges, we believe that React is a powerful tool for solving the problem of implementing and maintaining complex frontends. Structural subtlety is key, and with it there is a freedom to consider a myriad of state management options and pick whichever makes the most sense. Moving forward, it's important to recognize that as an open source community, we have options. When a tool stops solving the problem we hire it for, we can throw it out and try a new one. React doesn't stay from this, and neither does Grafana. But for now, we are happy with our decision to switch to React, and will continue to use it for as long as it makes sense to. If you're interested in learning more about Grafana and our new Dashboard Runtime Library themes, please check out the upcoming GrafanaCon conference.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

A Framework for Managing Technical Debt
TechLead Conference 2023TechLead Conference 2023
35 min
A Framework for Managing Technical Debt
Top Content
Let’s face it: technical debt is inevitable and rewriting your code every 6 months is not an option. Refactoring is a complex topic that doesn't have a one-size-fits-all solution. Frontend applications are particularly sensitive because of frequent requirements and user flows changes. New abstractions, updated patterns and cleaning up those old functions - it all sounds great on paper, but it often fails in practice: todos accumulate, tickets end up rotting in the backlog and legacy code crops up in every corner of your codebase. So a process of continuous refactoring is the only weapon you have against tech debt.In the past three years, I’ve been exploring different strategies and processes for refactoring code. In this talk I will describe the key components of a framework for tackling refactoring and I will share some of the learnings accumulated along the way. Hopefully, this will help you in your quest of improving the code quality of your codebases.

Debugging JS
React Summit 2023React Summit 2023
24 min
Debugging JS
Top Content
As developers, we spend much of our time debugging apps - often code we didn't even write. Sadly, few developers have ever been taught how to approach debugging - it's something most of us learn through painful experience.  The good news is you _can_ learn how to debug effectively, and there's several key techniques and tools you can use for debugging JS and React apps.
Monolith to Micro-Frontends
React Advanced Conference 2022React Advanced Conference 2022
22 min
Monolith to Micro-Frontends
Top Content
Many companies worldwide are considering adopting Micro-Frontends to improve business agility and scale, however, there are many unknowns when it comes to what the migration path looks like in practice. In this talk, I will discuss the steps required to successfully migrate a monolithic React Application into a more modular decoupled frontend architecture.
Power Fixing React Performance Woes
React Advanced Conference 2023React Advanced Conference 2023
22 min
Power Fixing React Performance Woes
Top Content
Next.js and other wrapping React frameworks provide great power in building larger applications. But with great power comes great performance responsibility - and if you don’t pay attention, it’s easy to add multiple seconds of loading penalty on all of your pages. Eek! Let’s walk through a case study of how a few hours of performance debugging improved both load and parse times for the Centered app by several hundred percent each. We’ll learn not just why those performance problems happen, but how to diagnose and fix them. Hooray, performance! ⚡️
Building a Voice-Enabled AI Assistant With Javascript
JSNation 2023JSNation 2023
21 min
Building a Voice-Enabled AI Assistant With Javascript
Top Content
In this talk, we'll build our own Jarvis using Web APIs and langchain. There will be live coding.
Video Editing in the Browser
React Summit 2023React Summit 2023
24 min
Video Editing in the Browser
Video editing is a booming market with influencers being all the rage with Reels, TikTok, Youtube. Did you know that browsers now have all the APIs to do video editing in the browser? In this talk I'm going to give you a primer on how video encoding works and how to make it work within the browser. Spoiler, it's not trivial!

Workshops on related topic

How to Solve Real-World Problems with Remix
Remix Conf Europe 2022Remix Conf Europe 2022
195 min
How to Solve Real-World Problems with Remix
Featured Workshop
Michael Carter
Michael Carter
- Errors? How to render and log your server and client errorsa - When to return errors vs throwb - Setup logging service like Sentry, LogRocket, and Bugsnag- Forms? How to validate and handle multi-page formsa - Use zod to validate form data in your actionb - Step through multi-page forms without losing data- Stuck? How to patch bugs or missing features in Remix so you can move ona - Use patch-package to quickly fix your Remix installb - Show tool for managing multiple patches and cherry-pick open PRs- Users? How to handle multi-tenant apps with Prismaa - Determine tenant by host or by userb - Multiple database or single database/multiple schemasc - Ensures tenant data always separate from others
Monitoring 101 for React Developers
React Advanced Conference 2023React Advanced Conference 2023
112 min
Monitoring 101 for React Developers
Top Content
WorkshopFree
Lazar Nikolov
Sarah Guthals
2 authors
If finding errors in your frontend project is like searching for a needle in a code haystack, then Sentry error monitoring can be your metal detector. Learn the basics of error monitoring with Sentry. Whether you are running a React, Angular, Vue, or just “vanilla” JavaScript, see how Sentry can help you find the who, what, when and where behind errors in your frontend project.
Building a Shopify App with React & Node
React Summit Remote Edition 2021React Summit Remote Edition 2021
87 min
Building a Shopify App with React & Node
Top Content
WorkshopFree
Jennifer Gray
Hanna Chen
2 authors
Shopify merchants have a diverse set of needs, and developers have a unique opportunity to meet those needs building apps. Building an app can be tough work but Shopify has created a set of tools and resources to help you build out a seamless app experience as quickly as possible. Get hands on experience building an embedded Shopify app using the Shopify App CLI, Polaris and Shopify App Bridge.We’ll show you how to create an app that accesses information from a development store and can run in your local environment.
Build a chat room with Appwrite and React
JSNation 2022JSNation 2022
41 min
Build a chat room with Appwrite and React
WorkshopFree
Wess Cope
Wess Cope
API's/Backends are difficult and we need websockets. You will be using VS Code as your editor, Parcel.js, Chakra-ui, React, React Icons, and Appwrite. By the end of this workshop, you will have the knowledge to build a real-time app using Appwrite and zero API development. Follow along and you'll have an awesome chat app to show off!
Hard GraphQL Problems at Shopify
GraphQL Galaxy 2021GraphQL Galaxy 2021
164 min
Hard GraphQL Problems at Shopify
WorkshopFree
Rebecca Friedman
Jonathan Baker
Alex Ackerman
Théo Ben Hassen
 Greg MacWilliam
5 authors
At Shopify scale, we solve some pretty hard problems. In this workshop, five different speakers will outline some of the challenges we’ve faced, and how we’ve overcome them.

Table of contents:
1 - The infamous "N+1" problem: Jonathan Baker - Let's talk about what it is, why it is a problem, and how Shopify handles it at scale across several GraphQL APIs.
2 - Contextualizing GraphQL APIs: Alex Ackerman - How and why we decided to use directives. I’ll share what directives are, which directives are available out of the box, and how to create custom directives.
3 - Faster GraphQL queries for mobile clients: Theo Ben Hassen - As your mobile app grows, so will your GraphQL queries. In this talk, I will go over diverse strategies to make your queries faster and more effective.
4 - Building tomorrow’s product today: Greg MacWilliam - How Shopify adopts future features in today’s code.
5 - Managing large APIs effectively: Rebecca Friedman - We have thousands of developers at Shopify. Let’s take a look at how we’re ensuring the quality and consistency of our GraphQL APIs with so many contributors.