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