This repository was archived by the owner on Jan 13, 2025. It is now read-only.
Commit 11cfae9 1 parent 512d76d commit 11cfae9 Copy full SHA for 11cfae9
File tree 8 files changed +39
-7
lines changed
8 files changed +39
-7
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
+ ## 0.1.5 / 2024-02-25
4
+
5
+ * [ ENHANCEMENT] Added support for exposing Prometheus metrics. The corresponding metrics are available under the path
6
+ ` /api-metrics ` . The ` /metrics ` endpoint is also accessible for exposing the metrics of the Prometheus server.
7
+ * [ BUGFIX] Fixed startup check of filesystem permissions in case of OSError.
8
+
3
9
## 0.1.4 / 2024-01-28
4
10
5
11
* [ ENHANCEMENT] Added HTTP query string: ` recreate=true|false ` for ` PUT /api/v1/rules/{file} ` endpoint.
Original file line number Diff line number Diff line change @@ -146,9 +146,9 @@ required parameters:
146
146
<!-- ROADMAP -->
147
147
## Roadmap
148
148
149
- - [ ] Add Prometheus instrumentation to expose metrics.
149
+ - [x ] Add Prometheus instrumentation to expose metrics.
150
150
- [ ] Add a Bulk API to allow the creation of multiple rules via a single API call.
151
- - [ ] Implement a way to update existing rules through the API.
151
+ - [x ] Implement a way to update existing rules through the API.
152
152
153
153
<!-- CONTACT -->
154
154
## Author and Maintainer
Original file line number Diff line number Diff line change 2
2
from src .utils .arguments import arg_parser
3
3
from src .api .v1 .api import api_router
4
4
from src .utils .openapi import openapi
5
+ from src .utils .metrics import metrics
5
6
from src .utils .log import logger
6
7
from src .utils import settings
7
8
from fastapi import FastAPI
12
13
prom_addr , rule_path = args .get ("prom.addr" ), args .get ("rule.path" )
13
14
host , port = args .get ("web.listen_address" ).split (":" )
14
15
15
- if False in [settings .check_prom_http_connection (prom_addr ),
16
+ if not all ( [settings .check_prom_http_connection (prom_addr ),
16
17
settings .check_reload_api_status (prom_addr ),
17
18
settings .check_rules_directory (rule_path ),
18
19
settings .check_fs_permissions (rule_path ),
19
- rule_schema_status ]:
20
+ rule_schema_status ]) :
20
21
sys .exit ()
21
22
22
23
@@ -26,6 +27,7 @@ def custom_openapi_wrapper():
26
27
27
28
app = FastAPI (swagger_ui_parameters = {"defaultModelsExpandDepth" : - 1 })
28
29
app .openapi = custom_openapi_wrapper
30
+ metrics (app )
29
31
app .include_router (api_router )
30
32
31
33
Original file line number Diff line number Diff line change
1
+ prometheus-fastapi-instrumentator == 6.1.0
1
2
python-json-logger == 2.0.7
2
3
email-validator == 2.0.0
3
4
fastapi == 0.109.0
Original file line number Diff line number Diff line change @@ -209,7 +209,7 @@ async def update(
209
209
return resp
210
210
211
211
response .status_code = status .HTTP_409_CONFLICT
212
- msg = f "The requested file already exists."
212
+ msg = "The requested file already exists."
213
213
logger .info (
214
214
msg = msg ,
215
215
extra = {
Original file line number Diff line number Diff line change
1
+ from prometheus_fastapi_instrumentator import PrometheusFastApiInstrumentator
2
+ from fastapi import FastAPI
3
+ from .log import logger
4
+ from sys import modules
5
+
6
+
7
+ def metrics (app : FastAPI ):
8
+ """
9
+ This function exposes Prometheus
10
+ metrics for prometheus-api service
11
+ """
12
+ metrics_path = "/api-metrics"
13
+ try :
14
+ instrumentator = PrometheusFastApiInstrumentator (
15
+ should_group_status_codes = False ,
16
+ excluded_handlers = ["/{path:path}" , "/.*metrics" ]
17
+ )
18
+ instrumentator .instrument (app )
19
+ instrumentator .expose (app , endpoint = metrics_path , tags = ["metrics" ])
20
+ except BaseException as e :
21
+ logger .error (f"{ modules [__name__ ], e } " )
22
+ else :
23
+ logger .info (f"Successfully started metrics endpoint at { metrics_path } path" )
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ def openapi(app: FastAPI):
16
16
"providing additional features and addressing its limitations. "
17
17
"Running as a sidecar alongside the Prometheus server enables "
18
18
"users to extend the capabilities of the API." ,
19
- version = "0.1.4 " ,
19
+ version = "0.1.5 " ,
20
20
contact = {
21
21
"name" : "Hayk Davtyan" ,
22
22
"url" : "https://hayk96.github.io" ,
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ def check_fs_permissions(prometheus_rules_dir) -> bool:
57
57
except OSError as e :
58
58
logger .error (
59
59
f"The temporary file could not be created or deleted for testing permissions. { e } " )
60
- return True
60
+ return False
61
61
else :
62
62
logger .debug (
63
63
"The application has the necessary permissions to access the rule files directory." )
You can’t perform that action at this time.
0 commit comments