Refactor filter_plugins
This commit is contained in:
parent
8ee096949d
commit
bdf1f8891b
14 changed files with 34 additions and 30 deletions
|
|
@ -4,7 +4,7 @@ lgtm_stack_mimir_domain: mimir.serguzim.me
|
|||
lgtm_stack_alloy_domain: alloy.serguzim.me
|
||||
lgtm_stack_loki_domain: "{{ all_services | service_get_domain('loki') }}"
|
||||
|
||||
lgtm_stack_alloy_jobs: "{{ all_services | services_to_alloy() }}"
|
||||
lgtm_stack_alloy_jobs: "{{ all_services | lgtm_stack_services_to_alloy() }}"
|
||||
|
||||
lgtm_stack_grafana_secret_key: "{{ undef() }}"
|
||||
|
||||
|
|
|
|||
44
playbooks/roles/lgtm_stack/filter_plugins/lgtm_stack.py
Normal file
44
playbooks/roles/lgtm_stack/filter_plugins/lgtm_stack.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
def transfer_optional_param(source, target, name, target_name=None):
|
||||
if param := source.get(name):
|
||||
target[target_name or name] = param
|
||||
|
||||
class FilterModule(object):
|
||||
def filters(self):
|
||||
return {
|
||||
'lgtm_stack_services_to_alloy': self.services_to_alloy,
|
||||
}
|
||||
|
||||
def services_to_alloy(self, services):
|
||||
result = []
|
||||
|
||||
for name, service in services.items():
|
||||
if not bool(service.get("host")):
|
||||
continue
|
||||
|
||||
if targets := service.get("metrics") or []:
|
||||
job = {
|
||||
"name": name,
|
||||
"targets": [],
|
||||
"scrape_interval": "60s",
|
||||
}
|
||||
|
||||
for target in targets:
|
||||
|
||||
address = target.get("address") or service["dns"][0]['domain']
|
||||
|
||||
transfer_optional_param(target, job, "interval", "scrape_interval")
|
||||
|
||||
new_target = {
|
||||
"address": address,
|
||||
"path": target["path"],
|
||||
"instance": name
|
||||
}
|
||||
|
||||
transfer_optional_param(target, new_target, "instance")
|
||||
transfer_optional_param(target, new_target, "job")
|
||||
|
||||
job["targets"].append(new_target)
|
||||
|
||||
result.append(job)
|
||||
|
||||
return result
|
||||
Loading…
Add table
Add a link
Reference in a new issue