{"id":20161682,"url":"https://github.com/jorgermduarte/prometheus-alerts-test","last_synced_at":"2026-04-12T18:11:39.252Z","repository":{"id":195351903,"uuid":"691636154","full_name":"jorgermduarte/prometheus-alerts-test","owner":"jorgermduarte","description":"Simple test project to test the grafana dashboard logs from servlet requests","archived":false,"fork":false,"pushed_at":"2023-09-20T22:02:02.000Z","size":144,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-02T10:46:58.568Z","etag":null,"topics":["alertmanager","app","docker","docker-compose","grafana","http","java","node","prometheus","requests","servlet"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jorgermduarte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-09-14T15:15:30.000Z","updated_at":"2023-10-02T09:15:10.000Z","dependencies_parsed_at":"2023-09-17T15:59:59.945Z","dependency_job_id":null,"html_url":"https://github.com/jorgermduarte/prometheus-alerts-test","commit_stats":{"total_commits":12,"total_committers":2,"mean_commits":6.0,"dds":0.08333333333333337,"last_synced_commit":"a4e0bf7a023a3383f099f145d53ce8bebd4f90fc"},"previous_names":["jorgermduarte/prometheus-alerts-test"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgermduarte%2Fprometheus-alerts-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgermduarte%2Fprometheus-alerts-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgermduarte%2Fprometheus-alerts-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgermduarte%2Fprometheus-alerts-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jorgermduarte","download_url":"https://codeload.github.com/jorgermduarte/prometheus-alerts-test/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241600483,"owners_count":19988713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alertmanager","app","docker","docker-compose","grafana","http","java","node","prometheus","requests","servlet"],"created_at":"2024-11-14T00:20:07.779Z","updated_at":"2026-04-12T18:11:39.222Z","avatar_url":"https://github.com/jorgermduarte.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Endpoint URI Tagging for Prometheus Metrics in Spring Boot\n\n## Problem Description\n\nWhen using Spring Boot with Prometheus for monitoring and metrics, you might encounter a situation where Prometheus registers requests with an \"UNKNOWN\" URI. This happens because, by default, Spring Boot does not provide Prometheus with endpoint information, leading to incomplete monitoring data.\n\n![Problem Screenshot](/images/problem_replication.png)\n\n## Solution\n\nTo resolve this issue and obtain accurate endpoint information in Prometheus, we can implement a URI tagging filter. This filter will capture incoming requests, extract their URIs, and tag the Prometheus metrics with the corresponding URIs. \n\n## Implementation\n\nIn your Spring Boot application, follow these steps:\n\n1. Create a controller that handles a generic route for various URIs:\n   \n   ```java\n   @RestController\n   @RequestMapping(\"/report/odata4\")\n   public class TestController {\n       @RequestMapping(\"/**\")\n       @GetMapping\n       @PostMapping\n       public void genericRoute(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {\n           resp.setContentType(\"text/html\");\n           try (final PrintWriter writer = resp.getWriter()) {\n               writer.println(\"\u003chtml\u003e\u003cbody\u003e\");\n               writer.println(\"\u003ch1\u003eHello, Controller\u003c/h1\u003e\");\n               writer.println(\"\u003c/body\u003e\u003c/html\u003e\");\n           }\n       }\n   }\n\n\n2. Create a configuration class that registers a UriTaggingFilter as a filter bean. This filter will tag Prometheus metrics with the request URI.\n    ```java\n    @Configuration\n    public class PrometheusUriFilterConfig {\n        @Bean\n        public FilterRegistrationBean\u003cUriTaggingFilter\u003e uriTaggingFilter(MeterRegistry meterRegistry) {\n            FilterRegistrationBean\u003cUriTaggingFilter\u003e registrationBean = new FilterRegistrationBean\u003c\u003e();\n            registrationBean.setFilter(new UriTaggingFilter(meterRegistry));\n            registrationBean.addUrlPatterns(\"/*\");\n            return registrationBean;\n        }\n\n        @WebFilter(\"/*\")\n        public static class UriTaggingFilter extends OncePerRequestFilter {\n            private final MeterRegistry meterRegistry;\n\n            public UriTaggingFilter(MeterRegistry meterRegistry) {\n                this.meterRegistry = meterRegistry;\n            }\n\n            @Override\n            protected void doFilterInternal(\n                    HttpServletRequest request,\n                    HttpServletResponse response,\n                    FilterChain filterChain) throws ServletException, IOException {\n\n                long startTime = System.currentTimeMillis();\n\n                try {\n                    filterChain.doFilter(request, response);\n                } finally {\n                    long endTime = System.currentTimeMillis();\n                    long requestTime = endTime - startTime;\n\n                    String uri = request.getRequestURI();\n\n                    Timer.builder(\"http.server.requests\")\n                            .tags(\"uri\", uri)\n                            .register(meterRegistry)\n                            .record(requestTime, TimeUnit.MILLISECONDS);\n                }\n            }\n        }\n    }\n    ```\n\nWith this configuration, your Prometheus metrics will now include accurate endpoint information.\n\n![Problem Screenshot](/images/problem_solution.png)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjorgermduarte%2Fprometheus-alerts-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjorgermduarte%2Fprometheus-alerts-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjorgermduarte%2Fprometheus-alerts-test/lists"}