Skip to content

Commit 7c630b0

Browse files
committed
Add endpoint configuration query
1 parent 315ce8f commit 7c630b0

File tree

5 files changed

+133
-1
lines changed

5 files changed

+133
-1
lines changed

lib/pbench/cli/server/shell.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ def main():
4141
"/run/pbench-server/gunicorn.pid",
4242
"--bind",
4343
f"{host}:{port}",
44-
"pbench.cli.server.shell:app())",
44+
"pbench.cli.server.shell:app()",
4545
]
4646
)

lib/pbench/server/api/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pbench.common.exceptions import BadConfig, ConfigFileNotSpecified
1414
from pbench.server.api.resources.upload_api import Upload, HostInfo
1515
from pbench.server.api.resources.graphql_api import GraphQL
16+
from pbench.server.api.resources.endpoint_configure import EndpointConfig
1617
from pbench.common.logger import get_pbench_logger
1718
from pbench.server.api.resources.query_apis.elasticsearch_api import Elasticsearch
1819
from pbench.server.api.resources.query_apis.query_controllers import QueryControllers
@@ -33,6 +34,11 @@ def register_endpoints(api, app, config):
3334
api.add_resource(
3435
HostInfo, f"{base_uri}/host_info", resource_class_args=(config, app.logger),
3536
)
37+
api.add_resource(
38+
EndpointConfig,
39+
f"{base_uri}/endpoints",
40+
resource_class_args=(config, app.logger),
41+
)
3642
api.add_resource(
3743
Elasticsearch,
3844
f"{base_uri}/elasticsearch",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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"{host}"
26+
uri_prefix = config.rest_uri
27+
self.uri = f"{host}:{port}{uri_prefix}"
28+
self.prefix = get_index_prefix(config)
29+
30+
def get(self):
31+
"""
32+
Return server configuration information required by the UI
33+
dashboard. This includes
34+
35+
prefix: The indexing prefix applied by the server to partition a
36+
shared Elasticsearch cluster index namespace.
37+
elasticsearch: The Pbench pass-through URI for the Elasticsearch
38+
cluster. This will eventually be superceded by the native
39+
Pbench APIs, though might remain accessible with special
40+
user/group privileges to support special cases?
41+
graphql: The GraphQL frontend on postgreSQL currently used by the
42+
dashboard user mocks. This will be superceded and decprecated
43+
by native Pbench user management APIs.
44+
results: Direct access to Pbench data sets for the dashboard; this is
45+
likely also something that should be superceded, as Pbench
46+
will need to be a front-end for future S3 storage schemas.
47+
result_index: The "root" index name for Pbench result data,
48+
qualified by the current index version. (TODO: I'm exposing
49+
these separately as the current dashboard config file does,
50+
but would it make more sense to prepend the index instead of
51+
exposing that separately?)
52+
result_sample_index: The "result-data" index has been broken into
53+
"result-data" and "result-data-sample" indices for the
54+
Elasticsearch V7 transition. TODO: If we update the dashboard
55+
queries without full migration to native Pbench APIs, it'll
56+
need this.
57+
run_index: The "master" run-data index root.
58+
run_toc_index: The Elasticsearch V7 index for run TOC data; again, the
59+
dashboard will need this if we don't move directly to native
60+
Pbench APIs.
61+
api: This is perhaps of questionable value. It's the root URL for
62+
all native Pbench APIs... including this one... which means
63+
the dashboard will need to configure this with an environment
64+
variable in order to query the rest.
65+
66+
Meta TODO: We're giving the pass-through APIs for Elasticsearch and
67+
GraphQL here, which implies adoption of Nikhil's and Fuqing's work to
68+
move the dashboard away from direct access to the backend DB servers.
69+
The alternative would be to expose the direct Elasticsearch and GraphQL
70+
URIs here.
71+
"""
72+
try:
73+
endpoints = {
74+
"prefix": self.prefix,
75+
"elasticsearch": f"{self.uri}/elasticsearch",
76+
"graphql": f"{self.uri}/graphql",
77+
"results": f"{self.host}:8901",
78+
"result_index": "v4.result-data.",
79+
"result_sample_index": "v4.result-data-sample.",
80+
"run_index": "v6.run-data.",
81+
"run_toc_index": "v6.run-toc.",
82+
"api": f"{self.uri}",
83+
}
84+
response = jsonify(endpoints)
85+
except Exception:
86+
self.logger.exception("Something went wrong constructing the endpoint info")
87+
abort(500, message="INTERNAL ERROR")
88+
else:
89+
response.status_code = 200
90+
return response
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
expected_results = {
22+
"prefix": get_index_prefix(server_config),
23+
"elasticsearch": f"{uri}/elasticsearch",
24+
"graphql": f"{uri}/graphql",
25+
"results": f"{host}:8901",
26+
"result_index": "v4.result-data.",
27+
"result_sample_index": "v4.result-data-sample.",
28+
"run_index": "v6.run-data.",
29+
"run_toc_index": "v6.run-toc.",
30+
"api": f"{uri}",
31+
}
32+
33+
response = client.get(f"{server_config.rest_uri}/endpoints")
34+
res_json = response.json
35+
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)