Skip to content

Commit

Permalink
Merge pull request mweinelt#36 from mweinelt/lint-action
Browse files Browse the repository at this point in the history
Add ci checks
  • Loading branch information
mweinelt authored Nov 12, 2023
2 parents ca22d2a + f19c2d8 commit 2f74508
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 40 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Lint"

on:
push:
pull_request:

jobs:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v19
with:
nix_path: nixpkgs=channel:nixpkgs-unstable
- run: |
nix flake check -L
33 changes: 8 additions & 25 deletions kea_exporter/base_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ def __init__(self):
def setup_dhcp4_metrics(self):
self.metrics_dhcp4 = {
# Packets
"sent_packets": Gauge(
f"{self.prefix_dhcp4}_packets_sent_total", "Packets sent", ["operation"]
),
"sent_packets": Gauge(f"{self.prefix_dhcp4}_packets_sent_total", "Packets sent", ["operation"]),
"received_packets": Gauge(
f"{self.prefix_dhcp4}_packets_received_total",
"Packets received",
Expand Down Expand Up @@ -225,9 +223,7 @@ def setup_dhcp4_metrics(self):
def setup_dhcp6_metrics(self):
self.metrics_dhcp6 = {
# Packets sent/received
"sent_packets": Gauge(
f"{self.prefix_dhcp6}_packets_sent_total", "Packets sent", ["operation"]
),
"sent_packets": Gauge(f"{self.prefix_dhcp6}_packets_sent_total", "Packets sent", ["operation"]),
"received_packets": Gauge(
f"{self.prefix_dhcp6}_packets_received_total",
"Packets received",
Expand Down Expand Up @@ -481,12 +477,8 @@ def parse_metrics(self, dhcp_version, arguments, subnets):

subnet_data = subnets.get(subnet_id, [])
if not subnet_data:
if subnet_id not in self.subnet_missing_info_sent.get(
dhcp_version, []
):
self.subnet_missing_info_sent.get(dhcp_version, []).append(
subnet_id
)
if subnet_id not in self.subnet_missing_info_sent.get(dhcp_version, []):
self.subnet_missing_info_sent.get(dhcp_version, []).append(subnet_id)
click.echo(
"Ignoring metric because subnet vanished from configuration:",
f"\tdhcp_version: {dhcp_version.name}, subnet_id: {subnet_id}",
Expand All @@ -501,18 +493,11 @@ def parse_metrics(self, dhcp_version, arguments, subnets):
if pool_index:
# Matched for subnet pool metrics
pool_index = int(pool_index)
subnet_pools = [
pool.get("pool") for pool in subnet_data.get("pools", [])
]
subnet_pools = [pool.get("pool") for pool in subnet_data.get("pools", [])]

if len(subnet_pools) <= pool_index:
if (
f"{subnet_id}-{pool_index}"
not in self.subnet_missing_info_sent.get(dhcp_version, [])
):
self.subnet_missing_info_sent.get(dhcp_version, []).append(
f"{subnet_id}-{pool_index}"
)
if f"{subnet_id}-{pool_index}" not in self.subnet_missing_info_sent.get(dhcp_version, []):
self.subnet_missing_info_sent.get(dhcp_version, []).append(f"{subnet_id}-{pool_index}")
click.echo(
"Ignoring metric because subnet vanished from configuration:",
f"\tdhcp_version: {dhcp_version.name}, subnet_id: {subnet_id}, pool_idx: {pool_index}",
Expand Down Expand Up @@ -551,9 +536,7 @@ def parse_metrics(self, dhcp_version, arguments, subnets):
labels.update(metric_info.get("labels", {}))

# Filter labels that are not configured for the metric
labels = {
key: val for key, val in labels.items() if key in metric._labelnames
}
labels = {key: val for key, val in labels.items() if key in metric._labelnames}

# export labels and value
metric.labels(**labels).set(value)
12 changes: 3 additions & 9 deletions kea_exporter/kea_http_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def load_modules(self):
)
config = r.json()
for module in config[0]["arguments"]["Control-agent"]["control-sockets"]:
if (
"dhcp" in module
): # Does not support d2 metrics. # Does not handle ctrl sockets that are offline
if "dhcp" in module: # Does not support d2 metrics. # Does not handle ctrl sockets that are offline
self.modules.append(module)

def load_subnets(self):
Expand All @@ -37,13 +35,9 @@ def load_subnets(self):
)
config = r.json()
for module in config:
for subnet in (
module.get("arguments", {}).get("Dhcp4", {}).get("subnet4", {})
):
for subnet in module.get("arguments", {}).get("Dhcp4", {}).get("subnet4", {}):
self.subnets.update({subnet["id"]: subnet})
for subnet in (
module.get("arguments", {}).get("Dhcp6", {}).get("subnet6", {})
):
for subnet in module.get("arguments", {}).get("Dhcp6", {}).get("subnet6", {}):
self.subnets6.update({subnet["id"]: subnet})

def update(self):
Expand Down
8 changes: 2 additions & 6 deletions kea_exporter/kea_socket_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def __init__(self, sock_path):
)
sys.exit(1)
except PermissionError:
click.echo(
f"Socket at {sock_path} is not read-/writeable.", file=sys.stderr
)
click.echo(f"Socket at {sock_path} is not read-/writeable.", file=sys.stderr)
sys.exit(1)

self.version = None
Expand Down Expand Up @@ -81,6 +79,4 @@ def __init__(self, sockets, **kwargs):

def update(self):
for kea in self.kea_instances:
self.parse_metrics(
kea.dhcp_version, kea.stats().get("arguments"), kea.subnets
)
self.parse_metrics(kea.dhcp_version, kea.stats().get("arguments"), kea.subnets)

0 comments on commit 2f74508

Please sign in to comment.