refactor(falco_metrics): put content type in documented constant

This will keep things clearer and also allow for easir update in
the future.

Signed-off-by: Samuel Gaist <samuel.gaist@idiap.ch>
This commit is contained in:
Samuel Gaist 2024-04-10 14:29:49 +02:00 committed by poiana
parent 9cc44c0eb7
commit a0c109fcff
3 changed files with 12 additions and 1 deletions

View File

@ -27,6 +27,15 @@ limitations under the License.
and falco libs into a string to be return by the metrics endpoint.
*/
/*!
\brief content_type to be returned by the webserver's metrics endpoint.
Currently it is the default Prometheus exposition format
https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format
*/
const std::string falco_metrics::content_type = "text/plain; version=0.0.4";
/*!
\brief Constructor that takes a \c state object to build its internal state
*/

View File

@ -27,6 +27,8 @@ namespace falco::app {
class falco_metrics
{
public:
static const std::string content_type;
falco_metrics(falco::app::state& state);
bool is_enabled() const { return m_metrics_enabled; };
std::string to_text() const;

View File

@ -69,7 +69,7 @@ void falco_webserver::start(
{
m_server->Get("/metrics",
[metrics](const httplib::Request &, httplib::Response &res) {
res.set_content(metrics.to_text(), "text/plain; version=0.0.4");
res.set_content(metrics.to_text(), falco_metrics::content_type);
});
}
// run server in a separate thread