Skip to content

Commit

Permalink
document histograms, add doh upstream test (#73)
Browse files Browse the repository at this point in the history
Also fixes #74
  • Loading branch information
cottand authored Nov 15, 2024
1 parent db020fc commit b2aa2c2
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 7 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/test-nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ jobs:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=channel:nixos-23.05
nix_path: nixpkgs=channel:nixos-24.05
github_access_token: ${{ secrets.GITHUB_TOKEN }}


- name: Enable KVM group perms (for NixOS tests)
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
sudo apt-get update
sudo apt-get install -y libvirt-clients libvirt-daemon-system libvirt-daemon virtinst bridge-utils qemu qemu-system-x86
sudo usermod -a -G kvm,libvirt $USER
- run: nix build . --show-trace

- run: nix flake check
6 changes: 4 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"strconv"
"strings"
"time"

"github.com/gin-gonic/gin"
"gopkg.in/gin-contrib/cors.v1"
Expand Down Expand Up @@ -48,8 +49,9 @@ func StartAPIServer(config *Config,
}

server := &http.Server{
Addr: config.API,
Handler: router,
Addr: config.API,
Handler: router,
ReadHeaderTimeout: time.Duration(config.Timeout) * time.Second,
}

router.Use(cors.Default())
Expand Down
1 change: 1 addition & 0 deletions doc/src/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ customdnsrecords = [
path = "/metrics"
# see https://cottand.github.io/leng/Prometheus-Metrics.html
highCardinalityEnabled = false
histogramsEnabled = false
resetPeriodMinutes = 60

[DnsOverHttpServer]
Expand Down
18 changes: 16 additions & 2 deletions doc/src/Prometheus-Metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ size of the `/metrics`
response will grow to be so big the metrics stop being updated.
While resetting the counters periodically can help
(and you can tweak that with the config `Metrics.resetPeriodMinutes`)
but you might still see issues depending on your traffic.
you might still see issues depending on your traffic.
You can
read [this SO post](https://stackoverflow.com/questions/46373442/how-dangerous-are-high-cardinality-labels-in-prometheus)
to learn more.
Expand All @@ -38,4 +38,18 @@ with the following config:
enabled = true
path = "/metrics"
highCardinalityEnabled = true
```
```

## Histogram metrics

Histogram metrics are not unbounded and usually will not be as high-cardinality as the metrics discussed above,
but you should still expect them to have some impact on leng's the memory footprint.

You can enable them with:

```toml
[Metrics]
enabled = true
path = "/metrics"
histogramsEnabled = true
```
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
metrics-api = pkgs.callPackage ./nixos-tests/metrics-api.nix { inherit self; };
systemctl-start = pkgs.callPackage ./nixos-tests/systemctl-start.nix { inherit self; };
custom-dns = pkgs.callPackage ./nixos-tests/custom-dns.nix { inherit self; };
doh-upstream = pkgs.callPackage ./nixos-tests/doh-upstream.nix { inherit self; };
};

}))
Expand Down
46 changes: 46 additions & 0 deletions nixos-tests/doh-upstream.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{ self, pkgs, home-manager, ... }:
let
nixpkgs = self.inputs.nixpkgs;
in
(nixpkgs.lib.nixos.runTest {
hostPkgs = pkgs;
defaults.documentation.enable = false;
node.specialArgs = { inherit self; };

name = "leng-custom-dns";

nodes = {
server = { config, pkgs, ... }: {
imports = [ self.nixosModules.default ];
# Open the default port for `postgrest` in the firewall
networking.firewall.allowedUDPPorts = [ 53 ];
networking.firewall.allowedTCPPorts = [ 80 ];

services.leng.enable = true;
services.leng.configuration = {
blocking.sourcesStore = "/tmp";
customdnsrecords = [];
upstream.DoH = "";
DnsOverHttpServer.enabled = true;
};
};

client = { pkgs, ... }: {
environment.systemPackages = [ pkgs.dig pkgs.curl ];
};
};

testScript =
''
start_all()
server.wait_for_unit("leng", timeout=10)
server.wait_for_open_port(80, timeout=10)
client.succeed(
'curl -vH "accept: application/dns-json" "http://server/dns-query?dns=AAABAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB"',
timeout=10,
)
'';

}).config.result
2 changes: 1 addition & 1 deletion nixos-tests/systemctl-start.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ in

services.leng.enable = true;
services.leng.configuration = {
blocking.sourcesStore="/tmp";
blocking.sourcesStore = "/tmp";
};
};

Expand Down

0 comments on commit b2aa2c2

Please sign in to comment.