Skip to content

Commit daf1108

Browse files
author
xavier
committed
locate operation has stage for grafana
1 parent ba6cea9 commit daf1108

19 files changed

+443
-141
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# How this works
2+
3+
The NMachine Prometheus Plugin has limited interoperability with
4+
Grafana. Namely, it provides a handy link (or port-forward),
5+
and it can report on the worload's health if it is in the cluster.
6+
7+
### If you don't have Grafana
8+
9+
That's okay. The plugin mainly uses the Prometheus API.

prom-plugin/kaml/prom_kaml/kaml.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import os
22
from typing import List, Dict, Type
33

4-
from kama_sdk.core.core.config_man import config_man
5-
64
from kama_sdk.core.core.kaml import KamlDescriptor
75
from kama_sdk.core.core import utils
86
from kama_sdk.model.base.model import Model

prom-plugin/kaml/prom_kaml/main/prom_client.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import json
21
import time
32
import traceback
43
from datetime import datetime, timedelta
54
from functools import lru_cache
65
from json import JSONDecodeError
7-
from typing import Optional, Dict, Tuple
6+
from typing import Optional, Dict, Tuple, Any
87
from urllib.parse import quote
98

109
import requests
@@ -49,27 +48,30 @@ def do_invoke(self, path: str, url_args: Dict) -> Optional[PromData]:
4948

5049
@lru_cache(maxsize=1)
5150
def find_server_svc(self) -> Optional[KatSvc]:
52-
if config := self.config():
53-
prom_ns = config.get(SVC_NS_KEY)
54-
prom_name = config.get(SVC_NAME_KEY)
51+
if self.config():
52+
prom_ns = self.read_config(SVC_NS_KEY)
53+
prom_name = self.read_config(SVC_NS_KEY)
5554
return KatSvc.find(prom_name, prom_ns)
5655

56+
def read_config(self, deep_key: str) -> Optional[Any]:
57+
return utils.deep_get2(self.config(), deep_key)
58+
5759
def config(self) -> Optional[Dict]:
5860
if self._config is None:
5961
root = config_man.manifest_variables(space='nmachine.prom')
6062
self._config = root
6163
return self._config
6264

6365
def is_prom_server_in_cluster(self) -> bool:
64-
return self.config().get(ACCESS_TYPE_KEY) == access_type_k8s
66+
return self.read_config(ACCESS_TYPE_KEY) == access_type_k8s
6567

6668
def get_base_in_cluster_url(self) -> str:
6769
if svc := self.find_server_svc():
6870
port = svc.first_tcp_port_num()
6971
return f"http://{svc.name}.{svc.namespace}:{port}"
7072

7173
def get_base_out_of_cluster_url(self) -> str:
72-
return self.config().get(URL_KEY)
74+
return self.read_config(URL_KEY)
7375

7476

7577
def instant_path_and_args(query: str, ts: datetime = None) -> Tuple:
@@ -145,7 +147,7 @@ def invoke_pure_http(path, args) -> Optional[Dict]:
145147
access_type_k8s = 'kubernetes'
146148
access_type_generic = 'generic'
147149

148-
URL_KEY = 'url'
149-
SVC_NS_KEY = 'service_namespace'
150-
SVC_NAME_KEY = 'service_name'
151-
ACCESS_TYPE_KEY = 'access_type'
150+
URL_KEY = 'prometheus.url'
151+
SVC_NS_KEY = 'prometheus.service_namespace'
152+
SVC_NAME_KEY = 'prometheus.service_name'
153+
ACCESS_TYPE_KEY = 'prometheus.access_type'

prom-plugin/kaml/prom_kaml/main/prom_data_supplier.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class PromDataSupplier(Supplier):
1212

1313
@cached_property
1414
def client(self) -> Optional[PromClient]:
15+
print("INIT CONFIG")
16+
print(self.client_config_root)
1517
if config := self.client_config_root:
1618
return PromClient(config)
1719
else:
@@ -58,8 +60,6 @@ def resolve(self) -> Union[PromMatrix, PromVector]:
5860
print(f"[kama_sdk:prom_supplier] bad req type {self._type}")
5961
response = None
6062

61-
print("sup RETURNNNNNNNNNNNNNNN")
62-
print(response)
6363
return response
6464

6565
def fetch_matrix(self) -> Optional[PromMatrix]:

prom-plugin/kaml/prom_kaml/yamls/operation/field-set.yaml

Whitespace-only changes.

prom-plugin/kaml/prom_kaml/yamls/operation/fields.yaml

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
kind: Operation
2+
id: nmachine.prom.operation.locate-existing
3+
title: Locate an existing Prometheus Server
4+
info: "Point the application to a Prometheus server that is already
5+
or is capable of monitoring the application"
6+
synopsis: assets::locate-existing-server.md
7+
tags: ['monitoring']
8+
labels:
9+
public: true
10+
stages:
11+
- id::nmachine.prom.stage.locate-existing-prom
12+
- id::nmachine.prom.stage.locate-existing-grafana
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
kind: Stage
2+
id: nmachine.prom.stage.locate-existing-grafana
3+
title: Locate Grafana Server
4+
info: "If you have a monitoring service inside
5+
or outside in your cluster,
6+
you can point this application to it in order to give
7+
Nectar data capabilities"
8+
9+
steps:
10+
- id: nmachine.prom.step.locate-existing-grafana
11+
title: Location the Grafana Homepage
12+
info: "State whether the server is inside or outside
13+
the cluster, and point to it."
14+
synopsis: assets::locate-existing-grafana.md
15+
16+
commit:
17+
standard:
18+
kind: MergeSupplier
19+
source: [get::props default_commit->.standard, {enabled: true}]
20+
21+
action:
22+
kind: MultiAction
23+
inherit: sdk.action.step_apply_application_manifest_e2e_action
24+
config_space: nmachine.prom
25+
26+
fields:
27+
- id::grafana.access_type
28+
- id::grafana.url
29+
- id::grafana.service_namespace
30+
- id::grafana.service_name
31+
32+
summary_desc: get::nmachine.prom.locate_op_summary
33+
34+
---
35+
36+
kind: Field
37+
id: grafana.access_type
38+
variable: id::grafana.access_type
39+
40+
---
41+
42+
kind: Field
43+
id: grafana.url
44+
variable: id::grafana.url
45+
visible:
46+
kind: Predicate
47+
challenge: get::props inputs->.grafana.access_type
48+
check_against: generic
49+
50+
---
51+
52+
kind: Field
53+
id: grafana.service_namespace
54+
variable: id::grafana.service_namespace
55+
visible:
56+
kind: Predicate
57+
challenge: get::props inputs->.grafana.access_type
58+
check_against: kubernetes
59+
60+
---
61+
62+
kind: Field
63+
id: grafana.service_name
64+
visible:
65+
kind: Predicate
66+
challenge: get::props inputs->.grafana.service_namespace
67+
operator: presence
68+
variable:
69+
kind: ManifestVariable
70+
inherit: grafana.service_name
71+
input:
72+
kind: SelectInput
73+
options:
74+
kind: ResourcesSupplier
75+
many: true
76+
selector:
77+
res_kind: Service
78+
namespace: "get::props inputs->.grafana.service_namespace"
79+
output: options_format
80+
serializer: legacy
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
kind: Stage
2+
id: nmachine.prom.stage.locate-existing-prom
3+
title: Locate Prometheus API
4+
info: "If you have a monitoring service inside
5+
or outside in your cluster,
6+
you can point this application to it in order to give
7+
Nectar data capabilities"
8+
9+
steps:
10+
- id: nmachine.prom.step.locate-existing-prom
11+
title: Locate Prometheus API
12+
info: "State whether the server is inside or outside
13+
the cluster, and point to it."
14+
synopsis: assets::locate-existing-server.md
15+
16+
commit:
17+
standard:
18+
kind: MergeSupplier
19+
source: [get::props default_commit->.standard, {enabled: true}]
20+
21+
action:
22+
kind: MultiAction
23+
inherit: sdk.action.step_apply_application_manifest_e2e_action
24+
config_space: nmachine.prom
25+
26+
fields:
27+
- id::prometheus.access_type
28+
- id::prometheus.url
29+
- id::prometheus.service_namespace
30+
- id::prometheus.service_name
31+
32+
summary_desc: get::nmachine.prom.locate_op_summary
33+
34+
---
35+
36+
id: sdk.misc.ping-monitoring-server
37+
kind: MultiAction
38+
sub_actions:
39+
- sdk.action.commit_step_values_action
40+
- kind: RunPredicatesAction
41+
title: Try to reach monitoring server
42+
info: Send HTTP to ${endpoint}
43+
endpoint: get::sdk.supplier.config.prefs .monitoring.url
44+
45+
---
46+
47+
kind: Field
48+
id: prometheus.access_type
49+
variable: id::prometheus.access_type
50+
51+
---
52+
53+
kind: Field
54+
id: prometheus.url
55+
variable: id::prometheus.url
56+
visible:
57+
kind: Predicate
58+
print_debug: [inputs]
59+
challenge: get::props inputs->.prometheus.access_type
60+
check_against: generic
61+
62+
---
63+
64+
kind: Field
65+
id: prometheus.service_namespace
66+
variable: id::prometheus.service_namespace
67+
visible:
68+
kind: Predicate
69+
print_debug: [inputs]
70+
challenge: get::props inputs->.prometheus.access_type
71+
check_against: kubernetes
72+
73+
---
74+
75+
kind: Field
76+
id: prometheus.service_name
77+
visible:
78+
kind: Predicate
79+
challenge: get::props inputs->.prometheus.service_namespace
80+
operator: presence
81+
variable:
82+
kind: ManifestVariable
83+
inherit: prometheus.service_name
84+
input:
85+
kind: SelectInput
86+
options:
87+
kind: ResourcesSupplier
88+
many: true
89+
selector:
90+
res_kind: Service
91+
namespace: "get::props inputs->.prometheus.service_namespace"
92+
output: options_format
93+
serializer: legacy

0 commit comments

Comments
 (0)