Skip to content

Commit ba6cea9

Browse files
author
xavier
committed
ping in operation working
1 parent 0d30fc2 commit ba6cea9

File tree

6 files changed

+141
-81
lines changed

6 files changed

+141
-81
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from kama_sdk.core.core import utils
1414
from kama_sdk.core.core.config_man import config_man
15+
from kama_sdk.core.core.utils import pwar
1516
from prom_kaml.main.types import PromData
1617

1718

@@ -60,7 +61,7 @@ def config(self) -> Optional[Dict]:
6061
return self._config
6162

6263
def is_prom_server_in_cluster(self) -> bool:
63-
return self.config().get(LOCATION_KEY, 'out') == 'in'
64+
return self.config().get(ACCESS_TYPE_KEY) == access_type_k8s
6465

6566
def get_base_in_cluster_url(self) -> str:
6667
if svc := self.find_server_svc():
@@ -102,11 +103,10 @@ def invoke_proxy_url(svc: KatSvc, path: str, url_args: Dict) -> Optional[Dict]:
102103
resp = svc.proxy_get(path, url_args) or {}
103104
if resp.get('status', 500) < 300:
104105
try:
105-
return json.loads(resp.get('body'))
106-
except JSONDecodeError:
107-
print(traceback.format_exc())
108-
print(resp.get('body'))
109-
print(f"[kama_sdk:prom_client] svc resp decode ^^ fail")
106+
body = resp.get('body')
107+
return body
108+
except:
109+
pwar(__name__, f"prom decode failed for resp {resp}", True)
110110
return None
111111

112112

@@ -142,8 +142,10 @@ def invoke_pure_http(path, args) -> Optional[Dict]:
142142

143143
prom_client = PromClient()
144144

145+
access_type_k8s = 'kubernetes'
146+
access_type_generic = 'generic'
145147

146148
URL_KEY = 'url'
147149
SVC_NS_KEY = 'service_namespace'
148150
SVC_NAME_KEY = 'service_name'
149-
LOCATION_KEY = 'relative_to_cluster'
151+
ACCESS_TYPE_KEY = 'access_type'

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def resolve(self) -> Union[PromMatrix, PromVector]:
5757
else:
5858
print(f"[kama_sdk:prom_supplier] bad req type {self._type}")
5959
response = None
60+
61+
print("sup RETURNNNNNNNNNNNNNNN")
62+
print(response)
6063
return response
6164

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

prom-plugin/kaml/prom_kaml/tests/prom_test_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def vanilla_setup():
1313
config_man.patch_user_vars({
14-
client_module.LOCATION_KEY: 'in',
14+
client_module.ACCESS_TYPE_KEY: client_module.access_type_k8s,
1515
client_module.SVC_NS_KEY: svc_ns,
1616
client_module.SVC_NAME_KEY: svc_name
1717
}, space='nmachine.prom')
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
kind: Field
2+
id: access_type
3+
config_space: nmachine.prom
4+
title: Where is the Prometheus server located?
5+
input: kind::SelectInput
6+
options:
7+
- id: kubernetes
8+
title: Inside the cluster
9+
- id: generic
10+
title: Outside the cluster
11+
12+
---
13+
14+
kind: Field
15+
id: url
16+
title: Data Source API's Base URL
17+
config_space: nmachine.prom
18+
visible:
19+
kind: Predicate
20+
challenge: get::props inputs->.access_type
21+
check_against: generic
22+
validators:
23+
- kind: FormatPredicate
24+
check_against: domain
25+
challenge: get::props inputs->.url
26+
27+
---
28+
29+
kind: Field
30+
id: service_namespace
31+
title: Namespace containing Prometheus Operator
32+
config_space: nmachine.prom
33+
visible:
34+
kind: Predicate
35+
challenge: get::props inputs->.access_type
36+
check_against: kubernetes
37+
variable:
38+
id: monitoring.service_namespace
39+
default: get::ns
40+
input:
41+
kind: SelectInput
42+
options:
43+
kind: ResourcesSupplier
44+
selector: "expr::Namespace:*"
45+
many: true
46+
output: options_format
47+
serializer: legacy
48+
49+
---
50+
51+
kind: Field
52+
id: service_name
53+
title: Prometheus Operator Service
54+
config_space: nmachine.prom
55+
visible:
56+
kind: Predicate
57+
challenge: get::props inputs->.service_namespace
58+
operator: presence
59+
input:
60+
kind: SelectInput
61+
options:
62+
kind: ResourcesSupplier
63+
many: true
64+
selector:
65+
res_kind: Service
66+
namespace: "get::props inputs->.service_namespace"
67+
output: options_format
68+
serializer: legacy

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

Lines changed: 14 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ sub_actions:
2020
title: Try to reach monitoring server
2121
info: Send HTTP to ${endpoint}
2222
endpoint: get::sdk.supplier.config.prefs .monitoring.url
23-
predicates:
24-
- nmachine.prom.predicate.is_prom_api_status_200
2523

2624
---
2725

@@ -39,71 +37,20 @@ steps:
3937
info: "State whether the server is inside or outside
4038
the cluster, and point to it."
4139
synopsis: assets::locate-existing-server.md
42-
action:
43-
kind: IfThenElse
44-
if_true: sdk.misc.ping-monitoring-server
45-
source:
46-
kind: Predicate
47-
challenge: get::props op_state->.monitoring.type
48-
check_against: disabled
49-
operator: not-equal
50-
fields:
51-
- kind: Field
52-
id: monitoring.relative_to_cluster
53-
title: Where is the Prometheus server located?
54-
input: kind::SelectInput
55-
options:
56-
- id: in
57-
title: Inside the Cluster
58-
- id: out
59-
title: Outside the Cluster
6040

61-
- kind: Field
62-
id: monitoring.url
63-
title: Data Source API's Base URL
64-
visible:
65-
kind: Predicate
66-
challenge: get::props inputs->.monitoring.relative_to_cluster
67-
check_against: out
68-
validators:
69-
- kind: FormatPredicate
70-
check_against: domain
71-
challenge: get::props inputs->.monitoring.url
72-
- challenge:
73-
inherit: nmachine.prom.predicate.is_prom_api_status_200
74-
endpoint: get::props inputs->.monitoring.url
41+
commit:
42+
standard:
43+
kind: MergeSupplier
44+
source: [get::props default_commit->.standard, {enabled: true}]
45+
action:
46+
kind: MultiAction
47+
inherit: sdk.action.step_apply_application_manifest_e2e_action
48+
config_space: nmachine.prom
7549

76-
- id: monitoring.service_namespace
77-
title: Namespace containing Prometheus Operator
78-
visible:
79-
kind: Predicate
80-
challenge: get::props inputs->.monitoring.relative_to_cluster
81-
check_against: in
82-
variable:
83-
id: monitoring.service_namespace
84-
default: get::ns
85-
input:
86-
kind: SelectInput
87-
options:
88-
kind: ResourcesSupplier
89-
selector: "expr::Namespace:*"
90-
many: true
91-
output: options_format
92-
serializer: legacy
50+
fields:
51+
- id::access_type
52+
- id::url
53+
- id::service_namespace
54+
- id::service_name
9355

94-
- id: monitoring.service_name
95-
title: Prometheus Operator Service
96-
visible:
97-
kind: Predicate
98-
challenge: get::props inputs->.monitoring.service_namespace
99-
operator: presence
100-
input:
101-
kind: SelectInput
102-
options:
103-
kind: ResourcesSupplier
104-
many: true
105-
selector:
106-
res_kind: Service
107-
namespace: "get::props inputs->.monitoring.service_namespace"
108-
output: options_format
109-
serializer: legacy
56+
summary_desc: get::nmachine.prom.locate_op_summary
Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,48 @@
1+
kind: Supplier
2+
id: nmachine.prom.locate_op_summary
3+
cached:
4+
ping_success: get::nmachine.prom.predicate.is_connected_from_input
5+
then_msg:
6+
kind: IfThenElse
7+
source: get::props ping_success
8+
if_true: yea dude
9+
if_false: nah bro
10+
source:
11+
kind: IfThenElse
12+
source: get::nmachine.prom.has_host_or_svc_inputs
13+
if_true:
14+
type: Line
15+
elements:
16+
- type: Text
17+
text: Still ${get::props then_msg}
18+
19+
---
20+
21+
kind: MultiPredicate
22+
id: nmachine.prom.has_host_or_svc_inputs
23+
operator: or
24+
source:
25+
- kind: Predicate
26+
operator: truthiness
27+
challenge: get::props inputs->.url
28+
- kind: Predicate
29+
operator: truthiness
30+
challenge: get::props inputs->.service_name
31+
32+
---
33+
134
kind: Predicate
2-
id: nmachine.prom.predicate.is_prom_api_status_200
35+
id: nmachine.prom.predicate.is_connected
336
challenge:
4-
kind: HttpDataSupplier
5-
property: status_code
6-
check_against: 200
7-
reason: "Endpoint did not return status code 200"
8-
tone: warning
37+
kind: PromDataSupplier
38+
type: ping
39+
print_debug: [type]
40+
operator: truthiness
41+
42+
---
43+
44+
kind: Predicate
45+
id: nmachine.prom.predicate.is_connected_from_input
46+
inherit: nmachine.prom.predicate.is_connected
47+
client_config: get::props inputs
48+
print_debug: [challenge, inputs]

0 commit comments

Comments
 (0)