|
| 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 |
0 commit comments