Skip to content
ImagineWorld

Troubleshooting, Implementing Best Practices, and More with Grafana

node_idnode-book_observability-with-grafana_chapter-15-troubleshooting-implementing-best-practices-and-more-with-gr
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num15
chapter_titleTroubleshooting, Implementing Best Practices, and More with Grafana
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

Chapter 15 — Troubleshooting, Implementing Best Practices, and More with Grafana

Section titled “Chapter 15 — Troubleshooting, Implementing Best Practices, and More with Grafana”

We are nearing the end of our journey in Observability with Grafana, so this is a good time to revisit some of the things we have learned. In this chapter, we will review the best practices for data collection and look at troubleshooting techniques that can help get your telemetry into Grafana. We will then move on to the Grafana stack for more best practices and troubleshooting with your telemetry backend, alerts, and dashboards. We will identify some of the pitfalls of observability and how to avoid them. Then, before wrapping up, we will look to the future and explore potential trends on the horizon.

In this chapter, we are going to cover the following main topics:

  • Best practices and troubleshooting for data collection
  • Best practices and troubleshooting for the Grafana stack
  • Avoiding pitfalls of observability
  • Future trends in application monitoring

Best practices and troubleshooting for data collection

Section titled “Best practices and troubleshooting for data collection”

Throughout this book, we have repeatedly talked about the importance of preparation, setting objectives, and defining requirements. Doing the upfront thought work cannot be underestimated, but sadly, it is often completely overlooked. There are far too many occasions where I have investigated a company’s observability platform and discovered collection agents have been deployed without thought, opening the floodgates to send everything into the backend. The price is an excess of undefined telemetry, making it hard to do your job and causing expensive operating and storage costs.

In this section, we’ll be sharing some best practices for data collection, together with some useful troubleshooting tips. Let’s first look at preparation activities for data collection.

Observability starts with a need or desire to monitor and observe systems, and to do that, we need data. However, too much data (and data for the sake of data) can break your system’s observability, which is why it is important to prepare. Set your objectives, considering what you want from your platform and who it is for. Instead of planning for the what if, plan for what is. You can always add to it later, which is much easier than taking away after the fact.

In Chapter 1, we introduced observability personas. You can use these to gather platform requirements. Ideally, you want to be able to answer the following questions:

  • Who are my observability customers?
  • What log formats do I want or have in my system?
  • What is the origin of the data?
  • What metrics are important for our service-level objectives (SLOs)?
  • Will tracing instrumentation help solve observability problems?
  • What data do I need for dashboards?

These answers will help you determine which agent technology works best for your use case, what log formats to use, and other important decisions.

Let’s look at some of the decisions we need to make for our data collection.

Several critical decisions must be made early on that can impact your entire observability journey. It is important to take the time upfront to make these decisions, as it becomes a lot harder and more expensive to change them later. In most scenarios, your choices are reduced, and you have to work with existing data. That does not stop you from identifying and communicating a new standard to aim for. Standardizing data collection across the entire organization provides a framework that supports engineers in compliance. Here, we group some of those factors together to help you process them:

  • Logs:
    • Choose a log format that can be extended so you can deliver quickly and enhance later.
      • Select labels carefully, considering Loki’s performance and cardinality. You can always extract additional fields as labels during querying.
      • Consider whether valuable metrics can be created from logs (to maximize the value).
  • Metrics:
    • Identify important metrics, and drop what you don’t need. This can help with metric cardinality, too. If you cannot drop the whole metric, just dropping some of the highest cardinality labels can help a lot.
      • Choose the protocols that provide the data you need (remember, there are variations, so read the documentation for each carefully).
      • If using verbose metric protocols, ensure protection is in place (e.g., histogram bucketing) to restrict the ability to flood your system.
      • Add context so you can correlate metrics with traces.
  • Traces:
    • Ensure that the accuracy of spans and traces is implemented and validated
      • Balance the performance and cost impact with a mitigation strategy (sampling, filtering, and retention)
  • Instrumentation libraries:
    • Research them well. If you are using a library, you want it to be maintained and supported going forward.
  • Telemetry collector:
    • Run proofs of concept to validate what works with your technology. You don’t want to fall foul of permission constraints restricting the choice of collector on your route to production.
      • Consider the support model that comes with the collector technology, if any.
      • What are your business needs from a collector?

Now that all the decisions have been made, let’s look at what to do if your telemetry is not showing up.

Within the observability platform, it can be difficult to isolate problems with your telemetry getting to the backend, especially if it is sent through different connections and components in your telemetry pipeline.

Here are a few steps that can help diagnose issues:

  • Check for error messages in the collector logs
  • Look for data rejections by Grafana, such as the following:
    • Sample too old
      • Trace too large
      • Ingest rate limiting
  • Validate authentication credentials (token expiry and permissions)
  • Verify how telemetry is being ingested (ports and protocols)
  • Analyze whether the telemetry is modified with sampling or redaction
  • Identify which exporters are being used to send telemetry to the next stage
  • Validate the telemetry format
  • Identify the next hop and validate its configuration
  • Test simple network connectivity and identify whether firewall rules or network policies are restricting data flow

We should, hopefully, have data in the backend now, so let’s look at some best practices with Grafana.

Best practices and troubleshooting for the Grafana stack

Section titled “Best practices and troubleshooting for the Grafana stack”

As with the previous section, the importance of preparation applies to the Grafana stack, as it does with any good system design. You are making decisions that affect your users, your data, and your costs. In this section, we’ll be sharing some best practices for preparing Grafana, together with some useful tips for debugging. Let’s first look at preparation activities for your Grafana stack.

When designing your platform, consider what you are sending there and who your users are. With your stack, it is important to consider wider subjects such as corporate authentication integration, as well as best endeavors to right-size your stack and implement processes to monitor that usage.

Ideally, you want to be able to answer the following questions:

  • Who needs to use the platform?
  • Where are they using the platform?
  • What data retention requirements exist (if any)?

There are important decisions to be made before you fully embrace your Grafana stack. Not all of them are related to observability; some are affected by regional governance and some are company policy. Working on and prioritizing these decisions earlier will help with the smooth running of your platform.

Here, we group some of those factors together to help you process them:

  • Architecture:
    • Does your use case require single or multiple stacks – for instance, in the case of data residency or the separation of development and production systems?
      • Is any data restricted and requires specific permissions, such as Personally Identifiable Information (PII) and the General Data Protection Regulation (GDPR)?
      • Are there global latency issues to consider?
      • Are there any user audit requirements?
  • Management:
    • Can the backend be outsourced to ease administration efforts?
      • Do you have the ability to fix problems in a timely manner in the case of an incident?
      • Would IaC provide platform control?
  • Authentication:
    • Can the platform be integrated with an authentication provider to make user management easier?
      • Do you have team-specific permissions that might cause issues with an identity provider?
  • Data retention:
    • You need to create data retention policies to understand why telemetry data is needed and for how long
      • Metrics are usually cheaper to store – you can generate these from logs with recording rules rather than store more expensive logs for longer

There are a few areas or touchpoints where problems can occur with your Grafana backend. The following techniques should help you get back on track or at least provide a point of reference to help you debug further:

  • Data collection: If you are having difficulties getting telemetry into Grafana, drop back to the APIs to send test data to validate network routes, API keys, and so on. This can be done with tools such as Postman or quite simply on the command line with curl.
  • Data querying: Sometimes, queries do not give you the results you expected or provide them in a timely manner. Here are a few steps that can help solve problems or diagnose them:
    • Break down large queries: Start small and build up your results, validating at each step by using short time ranges and stronger filters
      • Check function order: The order of query functions affects the outcome, in the same way that the order of equations affects the result in math
      • Speed up slow results: Results can be obtained more quickly by following these practices:
      • Check how many data points there are - Limit the maximum data points returned in query options - Increase the minimum interval timeout in query options - Use group by functions to reduce the result set If you are trying out different variations of your query, the Query history button will remember them for you.
  • Problem discovery: It is not always obvious where problems lie – unless, of course, people report them. Grafana provides a set of dashboards to support your success with Grafana Cloud. Here is a screenshot of the Grafana Cloud Dashboards list:

Figure 15.1 – Grafana Cloud Dashboards

When diagnosing problems with your Grafana data and dashboards, the Usage Insights dashboards can help. Navigate to the Usage Insights – 1 – Overview dashboard and scroll down; you will find three panels:

  • Top 10 dashboards with errors: This lets you know which dashboards are encountering errors of some form.
  • Top 10 data sources with errors: This reports the Grafana data sources that have issues. This is useful to diagnose errors with queries, or in communicating to the backend data source.
  • Top 10 users seeing errors: This identifies your platform users who are encountering problems inside Grafana. This is helpful when investigating platform stability.

These panels guide you to the issues being encountered with drill-down links into other dashboards to show specific errors to aid diagnosis.

In particular, the Grafana Cloud Billing/Usage dashboard is very important in showing why samples might be rejected due to hitting account limits. Additionally, the Cardinality management dashboards can help highlight problems where label values are causing issues.

Let’s now look at problems that we could encounter in the wider subject of observability.

We have identified several areas throughout this book where you need to sit down and think about your approach. All of these considerations contribute to your ongoing success with your observability platform. We will now call out a few of these, with some guidelines to follow:

  • Treat your platform as an evolving development; start with the basics and build upon that, continuously reviewing where you are. Reducing the time to value will ensure return on investment is being realized.
  • Collect requirements from multiple customers and then plan a roadmap that will deliver more value to more users to ensure the adoption and support of your platform.
  • Monitor costs, paying close attention to the data collection stage, where it is cheaper to fix. Use your observability tools to help.
  • Fix cardinality early, and develop standards that teams can work to that will control the problem. Additionally, you can apply governance that restricts data collection into the platform if it does not adhere to standards.
  • Isolate high-load, low-value environments (especially performance test environments) to protect business-critical system observability. You can build cheaper, short-lived observability systems for these environments to keep costs under control.
  • Define a 6- and 12-month roadmap. This will help you plan for and adapt to industry changes. Observability is moving fast, with new developments coming all the time; being agile will help you navigate them.
  • Monitor platform usage. Grafana provides some excellent dashboards, as shown in Figure 15*.1*, that help you understand what is being used and how. Additionally, you can enhance this by improving the monitoring of your collector estate to create visibility of your entire telemetry pipeline.

Let’s now look to the future and think about where observability could be heading.

It is difficult to present a perspective on future trends without being opinionated, so the following opinions reflect my beliefs on where the industry is heading:

We will now wrap up this chapter and the book. You should now have the knowledge to implement, troubleshoot, and manage Grafana for your observability journey.

In this chapter, we have gone over best practices and troubleshooting techniques for data collection and the Grafana stack. We have looked at ways to avoid the pitfalls of observability as a whole, wrapping the chapter up with a look at future trends in application monitoring. These sections should have given you insights that will support your observability platform being a success, and help you get value from your platform for your users quicker and more efficiently. Now that we’ve completed the final chapter in our journey together through Observability with Grafana, let’s take a moment to review our key learnings.

In the first part of the book, we introduced observability and Grafana, along with a look at application and infrastructure instrumentation. We closed that part by setting up the OpenTelemetry demonstration application in your own Kubernetes environment.

In part two, we worked through different telemetry types that you will encounter with Grafana – Loki for logs, Prometheus (Mimir) for metrics, and Tempo for traces – together making LGTM (Loki, Grafana, Tempo, Mimir), which you will see all over the Grafana website. We then looked at integrations with Kubernetes (which we used with the demo app throughout the book), AWS, GCP, and Azure.

In part three, we worked with Grafana more, presenting data with dashboards and building an incident management process with alerts. We then explored IaC for configuring Grafana, followed by a look at the architecture of the Grafana stack.

In our final part, we talked about real user monitoring with Grafana frontend observability, application profiling with Grafana Pyroscope, and performance testing with Grafana K6. We closed the book with a look at how DevOps can be supported with observability, followed by some best practices and troubleshooting in this chapter.

Technology in the observability space, and especially with Grafana, moves fast. Hopefully, we have provided you with some timeless approaches and techniques that you can develop to support your observability work. Your new friends, the observability personas, will be there to lend a hand when you need it. Thank you for allowing us to be part of this journey with you. Good luck!