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

rec: generate metrics files (also) where meson expects them #14941

Merged
merged 3 commits into from
Dec 10, 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
2 changes: 1 addition & 1 deletion pdns/recursordist/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ py = import('python')
python = py.find_installation('python3', required: true)

metricfiles = custom_target(
command: [python, '@INPUT0@', '@SOURCE_ROOT@'],
command: [python, '@INPUT0@', '@SOURCE_ROOT@', '@BUILD_ROOT@'],
input: metric_sources,
output: [
'rec-metrics-gen.h',
Expand Down
24 changes: 21 additions & 3 deletions pdns/recursordist/metrics.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import os
import sys
import shutil

# default: 'type': uint64
# ptype: "'counter' (vs gauge')

srcdir = '.'
if len(sys.argv) == 2:
print("metrics.py: using srcdir from arguments")
builddir = '.'
if len(sys.argv) == 3:
print("metrics.py: using srcdir and builddir from arguments")
srcdir = sys.argv[1]
builddir = sys.argv[2]

print("Generating metrics related files")
print("metrics.py cwd: " + os.getcwd())
print("metrics.py srcdir: " + srcdir + " = " + os.path.realpath(srcdir))
print("metrics.py builddir: " + builddir + " = " + os.path.realpath(builddir))

def dedashForSNMP(name):
cap = False
Expand All @@ -31,6 +35,10 @@ def dedashForSNMP(name):
with open(srcdir + '/metrics_table.py', mode='r', encoding="utf-8") as file:
table = eval(file.read())

#
# We create various files in the srcdir but copy them into the builddir if needed to satisfy meson
# FIXME: only generate in builddir once autotools have been dropped
#
with open(srcdir + '/rec-oids-gen.h', 'w', encoding='utf-8') as file:
file.write('// THIS IS A GENERATED FILE. DO NOT EDIT. SOURCE metrics.py AND metrics_table.py\n')
for entry in table:
Expand All @@ -44,6 +52,8 @@ def dedashForSNMP(name):
file.write(f'static const oid10 {name}OID = {{RECURSOR_STATS_OID, {snmp}}};\n')
if 'ifdef' in entry:
file.write(f'#endif\n')
if srcdir != builddir:
shutil.copy(srcdir + '/rec-oids-gen.h', builddir)

with open(srcdir + '/rec-snmp-gen.h', 'w', encoding='utf-8') as file:
file.write('// THIS IS A GENERATED FILE. DO NOT EDIT. SOURCE metrics.py AND metrics_table.py\n')
Expand All @@ -58,6 +68,8 @@ def dedashForSNMP(name):
file.write(f'registerCounter64Stat("{name}", {dname}OID);\n')
if 'ifdef' in entry:
file.write(f'#endif\n')
if srcdir != builddir:
shutil.copy(srcdir + '/rec-snmp-gen.h', builddir)

with open(srcdir + '/rec-prometheus-gen.h', 'w', encoding='utf-8') as file:
file.write('// THIS IS A GENERATED FILE. DO NOT EDIT. SOURCE metrics.py AND metrics_table.py\n')
Expand All @@ -75,6 +87,8 @@ def dedashForSNMP(name):
if 'ptype' in entry:
ptype = entry['ptype']
file.write(f'{{"{name}", MetricDefinition(PrometheusMetricType::{ptype}, "{desc}")}},\n')
if srcdir != builddir:
shutil.copy(srcdir + '/rec-prometheus-gen.h', builddir)

with open(srcdir + '/rec-metrics-gen.h', 'w', encoding='utf-8') as file:
file.write('// THIS IS A GENERATED FILE. DO NOT EDIT. SOURCE metrics.py AND metrics_table.py\n')
Expand All @@ -94,6 +108,8 @@ def dedashForSNMP(name):
file.write(f'}}\n')
if 'ifdef' in entry:
file.write(f'#endif\n')
if srcdir != builddir:
shutil.copy(srcdir + '/rec-metrics-gen.h', builddir)

if os.path.isdir(srcdir + '/docs'):
with open(srcdir + '/docs/rec-metrics-gen.rst', 'w', encoding='utf-8') as file:
Expand Down Expand Up @@ -155,9 +171,11 @@ def dedashForSNMP(name):
str2 += f',\n {name}'


with open(srcdir + '/RECURSOR-MIB.in', mode='r', encoding='UTF-8') as file:
with open(srcdir + '/RECURSOR-MIB.in', mode='r', encoding='utf-8') as file:
text = file.read()
text = text.replace('REPL_OBJECTS1', str1)
text = text.replace('REPL_OBJECTS2', str2)
with open(srcdir + '/RECURSOR-MIB.txt', 'w', encoding='utf-8') as file2:
file2.write(text)
if srcdir != builddir:
shutil.copy(srcdir + '/RECURSOR-MIB.txt', builddir)
Loading