Skip to content

Commit e5067eb

Browse files
committed
Add endpoint configuration query
1 parent 8795350 commit e5067eb

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed

lib/pbench/server/api/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from pbench.common.exceptions import BadConfig, ConfigFileNotSpecified
1515
from pbench.server.api.resources.upload_api import Upload, HostInfo
1616
from pbench.server.api.resources.graphql_api import GraphQL
17+
from pbench.server.api.resources.endpoint_configure import EndpointConfig
1718
from pbench.common.logger import get_pbench_logger
1819
from pbench.server.api.resources.query_apis.elasticsearch_api import Elasticsearch
1920
from pbench.server.api.resources.query_apis.query_controllers import QueryControllers
@@ -35,6 +36,11 @@ def register_endpoints(api, app, config):
3536
api.add_resource(
3637
HostInfo, f"{base_uri}/host_info", resource_class_args=(config, app.logger),
3738
)
39+
api.add_resource(
40+
EndpointConfig,
41+
f"{base_uri}/endpoints",
42+
resource_class_args=(config, app.logger),
43+
)
3844
api.add_resource(
3945
Elasticsearch,
4046
f"{base_uri}/elasticsearch",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
from flask_restful import Resource, abort
2+
from flask import jsonify
3+
4+
from pbench.server.api.resources.query_apis import get_index_prefix
5+
6+
7+
class EndpointConfig(Resource):
8+
"""
9+
EndpointConfig API resource: this supports dynamic dashboard configuration
10+
from the Pbench server rather than constructing a disconnected dashboard
11+
config file.
12+
"""
13+
14+
def __init__(self, config, logger):
15+
"""
16+
__init__ Construct the API resource
17+
18+
Args:
19+
config (PbenchServerConfig): server config values
20+
logger (Logger): message logging
21+
"""
22+
self.logger = logger
23+
port = config.get("pbench-server", "rest_port")
24+
host = config.get("pbench-server", "host")
25+
self.host = f"{str(host)}"
26+
self.port = port
27+
uri_prefix = config.rest_uri
28+
self.uri = f"{host}:{port}{uri_prefix}"
29+
self.prefix = get_index_prefix(config)
30+
self.commit_id = config.COMMIT_ID
31+
32+
def get(self):
33+
"""
34+
Return server configuration information required by the UI
35+
dashboard. This includes
36+
37+
metadata: Information about the server configuration
38+
prefix: The indexing prefix applied by the server to partition a
39+
shared Elasticsearch cluster index namespace.
40+
result_index: The "root" index name for Pbench result data,
41+
qualified by the current index version and prefix.
42+
result_sample_index: The "result-data" index has been broken into
43+
"result-data" and "result-data-sample" indices for the
44+
Elasticsearch V7 transition. TODO: If we update the dashboard
45+
queries without full migration to native Pbench APIs, it'll
46+
need this.
47+
run_index: The "master" run-data index root.
48+
run_toc_index: The Elasticsearch V7 index for run TOC data; again, the
49+
dashboard will need this if we don't move directly to native
50+
Pbench APIs.
51+
api: A list of the server APIs supported; we give a name, which
52+
corresponds to either the current config.json property name
53+
(e.g., "elasticsearch") or the current src/service method name
54+
being replaced (e.g., "queryControllers").
55+
results: Direct access to Pbench data sets for the dashboard; this
56+
is likely also something that should be superceded, as Pbench
57+
will need to be a front-end for future S3 storage schemas.
58+
elasticsearch: The Pbench pass-through URI for the Elasticsearch
59+
cluster. This will eventually be superceded by the native
60+
Pbench APIs, though might remain accessible with special
61+
user/group privileges to support special cases?
62+
graphql: The GraphQL frontend on postgreSQL currently used by the
63+
dashboard user mocks. This will be superceded and decprecated
64+
by native Pbench user management APIs.
65+
queryControllers: Return information about the run documents that
66+
were created within a specified range of months.
67+
68+
69+
Meta TODO: We're giving the pass-through APIs for Elasticsearch and
70+
GraphQL here, which implies adoption of Nikhil's and Fuqing's work to
71+
move the dashboard away from direct access to the backend DB servers.
72+
The alternative would be to expose the direct Elasticsearch and GraphQL
73+
URIs here.
74+
"""
75+
try:
76+
endpoints = {
77+
"metadata": {
78+
"identification": f"Pbench server {self.commit_id}",
79+
"prefix": self.prefix,
80+
"run_index": f"{self.prefix}.v6.run-data.",
81+
"run_toc_index": f"{self.prefix}.v6.run-toc.",
82+
"result_index": f"{self.prefix}.v4.result-data.",
83+
"result_sample_index": f"{self.prefix}.v4.result-data-sample.",
84+
},
85+
"api": {
86+
"results": f"{self.host}:8901",
87+
"elasticsearch": f"{self.uri}/elasticsearch",
88+
"endpoints": f"{self.uri}/endpoints",
89+
"graphql": f"{self.uri}/graphql",
90+
"queryControllers": f"{self.uri}/queryControllers",
91+
},
92+
}
93+
response = jsonify(endpoints)
94+
except Exception:
95+
self.logger.exception("Something went wrong constructing the endpoint info")
96+
abort(500, message="INTERNAL ERROR")
97+
else:
98+
response.status_code = 200
99+
return response
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from pbench.server.api.resources.query_apis import get_index_prefix
2+
3+
4+
class TestEnpointConfig:
5+
"""
6+
Unit testing for EndpointConfig class.
7+
8+
In a web service context, we access class functions mostly via the
9+
Flask test client rather than trying to directly invoke the class
10+
constructor and `post` service.
11+
"""
12+
13+
def test_query(self, client, server_config):
14+
"""
15+
test_query Check that endpoint data matches the config file.
16+
"""
17+
port = server_config.get("pbench-server", "rest_port")
18+
host = server_config.get("pbench-server", "host")
19+
uri_prefix = server_config.rest_uri
20+
uri = f"{host}:{port}{uri_prefix}"
21+
prefix = get_index_prefix(server_config)
22+
expected_results = {
23+
"metadata": {
24+
"identification": f"Pbench server {server_config.COMMIT_ID}",
25+
"prefix": prefix,
26+
"run_index": f"{prefix}.v6.run-data.",
27+
"run_toc_index": f"{prefix}.v6.run-toc.",
28+
"result_index": f"{prefix}.v4.result-data.",
29+
"result_sample_index": f"{prefix}.v4.result-data-sample.",
30+
},
31+
"api": {
32+
"results": f"{host}:8901",
33+
"elasticsearch": f"{uri}/elasticsearch",
34+
"endpoints": f"{uri}/endpoints",
35+
"graphql": f"{uri}/graphql",
36+
"queryControllers": f"{uri}/queryControllers",
37+
},
38+
}
39+
40+
response = client.get(f"{server_config.rest_uri}/endpoints")
41+
res_json = response.json
42+
assert res_json == expected_results

server/rpm/pbench-server.spec.j2

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ fi
131131
/%{installdir}/lib/pbench/server/api/__init__.py
132132
/%{installdir}/lib/pbench/server/api/resources/graphql_api.py
133133
/%{installdir}/lib/pbench/server/api/resources/upload_api.py
134+
/%{installdir}/lib/pbench/server/api/resources/endpoint_configure.py
134135
/%{installdir}/lib/pbench/server/api/resources/query_apis/__init__.py
135136
/%{installdir}/lib/pbench/server/api/resources/query_apis/elasticsearch_api.py
136137
/%{installdir}/lib/pbench/server/api/resources/query_apis/query_controllers.py

0 commit comments

Comments
 (0)