Skip to content

Commit e5db89d

Browse files
authored
Merge pull request #40 from aiven/parse-replicas
Added parsing of nodes and replicas
2 parents 2d38250 + 77be239 commit e5db89d

File tree

5 files changed

+60
-34
lines changed

5 files changed

+60
-34
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,8 @@ Contact
100100
Bug reports and patches are very welcome, please post them as GitHub issues and pull requests at https://github.com/aiven/metadata-parser .
101101
To report any possible vulnerabilities or other serious issues please see our [security](SECURITY.md) policy.
102102

103+
All images under the `src` folder and shown in `nx.html` file are taken from https://www.flaticon.com/
104+
All images under the `src/services` folder are a property of Aiven
105+
103106

104107
Apache, Apache Kafka, Kafka, Apache Flink, Flink, Apache Cassandra, and Cassandra are either registered trademarks or trademarks of the Apache Software Foundation in the United States and/or other countries. ClickHouse is a registered trademark of ClickHouse, Inc. https://clickhouse.com. M3, M3 Aggregator, M3 Coordinator, OpenSearch, PostgreSQL, MySQL, InfluxDB, Grafana, Terraform, and Kubernetes are trademarks and property of their respective owners. *Redis is a trademark of Redis Ltd. and the Redis box logo is a mark of Redis Ltd. Any rights therein are reserved to Redis Ltd. Any use by Aiven is for referential purposes only and does not indicate any sponsorship, endorsement or affiliation between Redis and Aiven. All product and service names used in this website are for identification purposes only and do not imply endorsement.

img/images.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
All images are taken from https://www.flaticon.com/

img/servers.png

18 KB
Loading

src/explore_service.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def explore(self, service_type, service_name, project):
110110
f"Don't know how to explore RUNNING {service_type}"
111111
f"service {service_name}"
112112
)
113-
print("AAAAA" + traceback.format_exc())
113+
114114
return nodes, edges
115115

116116
try:
@@ -136,6 +136,15 @@ def explore(self, service_type, service_name, project):
136136
"label": service_name,
137137
}
138138
)
139+
140+
# Getting components
141+
142+
(new_nodes, new_edges) = explore_components(
143+
service_name, service_type, service["components"]
144+
)
145+
nodes = nodes + new_nodes
146+
edges = edges + new_edges
147+
139148
# Getting integrations
140149

141150
(new_nodes, new_edges) = integration.explore_integrations(
@@ -348,3 +357,44 @@ def explore_ext_endpoints(self, project):
348357
)
349358

350359
return nodes, edges
360+
361+
362+
def explore_components(service_name, service_type, components):
363+
nodes = []
364+
edges = []
365+
366+
global SERVICE_MAP
367+
368+
for component in components:
369+
nodes.append(
370+
{
371+
"id": service_type
372+
+ "~"
373+
+ service_name
374+
+ "~node~"
375+
+ component.get("host"),
376+
"host": component.get("host"),
377+
"port": component.get("port"),
378+
"privatelink_connection_id": component.get(
379+
"privatelink_connection_id"
380+
),
381+
"route": component.get("route"),
382+
"usage": component.get("usage"),
383+
"type": "service_node",
384+
"service_type": service_type,
385+
"label": component.get("host"),
386+
}
387+
)
388+
edges.append(
389+
{
390+
"from": service_type
391+
+ "~"
392+
+ service_name
393+
+ "~node~"
394+
+ component.get("host"),
395+
"to": service_name,
396+
"label": "partition",
397+
}
398+
)
399+
SERVICE_MAP[component.get("host")] = service_name
400+
return nodes, edges

src/pyvis_display.py

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
colors["backup"] = "cccccc"
2929
colors["consumer_group"] = "#0000cc"
3030
colors["partition"] = "#0000cc"
31+
colors["service_nodes"] = "#0000cc"
3132

3233

3334
sizes = {}
@@ -56,6 +57,7 @@
5657
sizes["backup"] = 10
5758
sizes["consumer_group"] = 10
5859
sizes["partition"] = 10
60+
sizes["service_node"] = 10
5961

6062

6163
images = {}
@@ -85,6 +87,7 @@
8587
images["backup"] = "img/database.png"
8688
images["consumer_group"] = "img/user.png"
8789
images["partition"] = "img/layout.png"
90+
images["service_node"] = "img/servers.png"
8891

8992

9093
def pyviz_graphy(nodes, edges):
@@ -160,7 +163,7 @@ def pyviz_graphy(nodes, edges):
160163

161164
print("Writing NX file")
162165
try:
163-
nt = Network(height="1200px", width="1600px", font_color="#000000")
166+
nt = Network(height="1000px", width="1000px", font_color="#000000")
164167
nt.from_nx(g)
165168
# nt.show_buttons()
166169
nt.show_buttons()
@@ -169,35 +172,4 @@ def pyviz_graphy(nodes, edges):
169172
except Exception as err:
170173
print(f"Error writing NX file: {err.__class__.__name__} {err}")
171174

172-
"""
173-
not_services = (n for n in g if g.nodes[n]['type'] != 'service')
174-
services = (n for n in g if g.nodes[n]['type'] == 'service')
175-
176-
g_connected = node_connected_component(g.to_undirected().subgraph(not_services),'pg~demo-pg~schema~public~table~pasta')
177-
#g_connected = (n for n in g_connected if g_connected[n]['type'] in ('service',''))
178-
g_subgraph = g.subgraph(g_connected)
179-
nt = Network(height='1200px', width='800px', font_color="#000000")
180-
nt.from_nx(g_subgraph)
181-
nt.show('filtered.html')
182-
content = '<table><tr><td ><div id = "mynetwork"></div></td><td ><div><table style="order-spacing: 0px; border-collapse: collapse; width: 100%; max-width: 100%; margin-bottom: 15px; background-color: transparent; text-align: left;">' \
183-
'<tr><th style="font-weight: bold; border: 1px solid #cccccc; padding: 8px;"><b>Img</b></th><th style="font-weight: bold; border: 1px solid #cccccc; padding: 8px;"><b>Node type</b></th><th style="font-weight: bold; border: 1px solid #cccccc; padding: 8px;"><b>Node Label</b></th><th style="font-weight: bold; border: 1px solid #cccccc; padding: 8px;"><b>Service type</b></td><th style="font-weight: bold; border: 1px solid #cccccc; padding: 8px;"><b>Service Name</b></th></tr>'
184-
for node in g_subgraph.nodes:
185-
186-
content = content + '<tr><td style="border: 1px solid #cccccc; padding: 8px;"><img src="'+g_subgraph.nodes[node]["image"]+'" width="20px" ></img></td><td style="border: 1px solid #cccccc; padding: 8px;">'+g_subgraph.nodes[node]["type"]+'</td><td style="border: 1px solid #cccccc; padding: 8px;">'+g_subgraph.nodes[node]["label"]+'</td><td style="border: 1px solid #cccccc; padding: 8px;">'+g_subgraph.nodes[node]["service_type"]+'</td><td style="border: 1px solid #cccccc; padding: 8px;">'+g_subgraph.nodes[node]["id"].split('~')[1]+'</td></tr>'
187-
content = content + '</table></div></table>'
188-
file = open("filtered.html", "r")
189-
190-
191-
replacement = ""
192-
# using the for loop
193-
for line in file:
194-
line = line.strip()
195-
changes = line.replace('<div id = "mynetwork"></div>', content)
196-
replacement = replacement + changes + "\n"
197-
198-
file.close()
199-
# opening the file in write mode
200-
fout = open("filtered.html", "w")
201-
fout.write(replacement)
202-
fout.close()
203-
"""
175+
## All images are taken from https://www.flaticon.com/

0 commit comments

Comments
 (0)