Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tempo service #192

Merged
merged 4 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
# created when `just run ex-*` is used
/example/share-services/pgweb/data/
/example/simple/data/
/example/grafana-tempo/data/

/.pre-commit-config.yaml
1 change: 1 addition & 0 deletions doc/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ short-title: Services
- [[redis-cluster]]
- [[zookeeper]]#
- [[grafana]]#
- [[tempo]]
- [[prometheus]]#
- [[cassandra]]#

Expand Down
36 changes: 36 additions & 0 deletions doc/tempo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Grafana Tempo

[Grafana Tempo](https://grafana.com/docs/tempo/latest/) is an open-source, easy-to-use, and high-scale distributed tracing backend. Tempo lets you search for traces, generate metrics from spans, and link your tracing data with logs and metrics.

## Getting Started

```nix
# In `perSystem.process-compose.<name>`
{
services.tempo."tp1".enable = true;
}
```

{#tips}
## Tips & Tricks

{#usage-with-grafana}
### Usage with Grafana

To add tempo as a datasource to #[[grafana]], we can use the following config:

```nix
{
services.tempo.tp1.enable = true;
services.grafana.gf1 = {
enable = true;
datasources = with config.services.tempo.tp1; [{
name = "Tempo";
type = "tempo";
access = "proxy";
url = "http://${httpAddress}:${builtins.toString httpPort}";
}];
};
settings.processes."gf1".depends_on."tp1".condition = "process_healthy";
}
```
105 changes: 105 additions & 0 deletions example/grafana-tempo/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions example/grafana-tempo/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
description = "A demo of grafana with tempo";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
services-flake.url = "git+file:///Volumes/Code/services-flake";
};
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
imports = [
inputs.process-compose-flake.flakeModule
];
perSystem = { self', pkgs, lib, ... }: {
# `process-compose.foo` will add a flake package output called "foo".
# Therefore, this will add a default package that you can build using
# `nix build` and run using `nix run`.
process-compose."default" = { config, ... }: {
imports = [
inputs.services-flake.processComposeModules.default
];

services.tempo."tp1".enable = true;
services.grafana."gf1" = {
enable = true;
datasources = with config.services.tempo.tp1; [{
name = "Tempo";
type = "tempo";
access = "proxy";
url = "http://${httpAddress}:${builtins.toString httpPort}";
}];
};
};

devShells.default = pkgs.mkShell {
nativeBuildInputs = [ pkgs.just ];
};
};
};
}
2 changes: 2 additions & 0 deletions example/grafana-tempo/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
default:
nix run
1 change: 1 addition & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ in
./prometheus.nix
./pgadmin.nix
./cassandra.nix
./tempo.nix
];
}
47 changes: 46 additions & 1 deletion nix/grafana.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
let
inherit (lib) types;
iniFormat = pkgs.formats.ini { };
yamlFormat = pkgs.formats.yaml { };
in
{
options = {
Expand Down Expand Up @@ -48,6 +49,32 @@ in
'';
};

datasources = lib.mkOption {
type = types.listOf yamlFormat.type;
description = "List of data sources to configure.";
default = [ ];
example = ''
[
{
name = "Tempo";
type = "tempo";
access = "proxy";
}
]
'';
};

deleteDatasources = lib.mkOption {
type = types.listOf yamlFormat.type;
description = "List of data sources to remove.";
default = [ ];
example = ''
[
{ name = "Tempo"; }
]
'';
};

outputs.settings = lib.mkOption {
type = types.deferredModule;
internal = true;
Expand All @@ -63,6 +90,23 @@ in
}
config.extraConf;
grafanaConfigIni = iniFormat.generate "defaults.ini" grafanaConfig;
provisioningConfig = pkgs.stdenv.mkDerivation {
name = "grafana-provisioning";
datasourcesYaml = yamlFormat.generate "datasources.yaml" {
apiVersion = 1;
deleteDatasources = config.deleteDatasources;
datasources = config.datasources;
};
buildCommand = ''
mkdir -p $out
mkdir -p $out/alerting
mkdir -p $out/dashboards
mkdir -p $out/datasources
ln -s "$datasourcesYaml" "$out/datasources/datasources.yaml"
mkdir -p $out/notifiers
mkdir -p $out/plugins
'';
};
startScript = pkgs.writeShellApplication {
name = "start-grafana";
runtimeInputs =
Expand All @@ -73,7 +117,8 @@ in
text = ''
grafana server --config ${grafanaConfigIni} \
--homepath ${config.package}/share/grafana \
cfg:paths.data="$(readlink -m ${config.dataDir})"
cfg:paths.data="$(readlink -m ${config.dataDir})" \
cfg:paths.provisioning="${provisioningConfig}"
'';
};
in
Expand Down
Loading
Loading