Skip to content

Commit

Permalink
Add grouping of metrics by endpoints
Browse files Browse the repository at this point in the history
Collecting metrics from each endpoint is a bad practice (if the service
is on a public network, it can be attacked, scanned, etc).

Now the metrics will be grouped by handler functions and will not grow.

For example:

    @app.get('/')
    def index():
        ...

    @app.post('/')
    def webhook():
        ...

If you try to scan/hack (i.e. send a lot of requests), you will have
only two metrics for the two paths:

    flask_http_<...>{endpoint="index", method="GET", status="404"}
    flask_http_<...>{endpoint="webhook", method="GET", status="404"}

instead of N metrics for the two paths, where N is count of requests:

    flask_http_<...>{method="GET",path="/foo",status="404"}
    flask_http_<...>{method="POST",path="/bar",status="404"}

Close #34
  • Loading branch information
Oleg Chaplashkin authored and ochaplashkin committed Nov 9, 2023
1 parent 59c11dd commit b721d19
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docbot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
}
apm = ElasticAPM(app, logging=True)

metrics = PrometheusMetrics(app)
metrics = PrometheusMetrics(app, group_by='endpoint')

@app.route("/", methods=['GET'])
@metrics.do_not_track()
def index() -> str:
return list_events_handler()

Expand Down

0 comments on commit b721d19

Please sign in to comment.