• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stacks-network / stacks-core / 23943270448

03 Apr 2026 10:32AM UTC coverage: 77.559% (-8.2%) from 85.712%
23943270448

Pull #7077

github

52f01d
web-flow
Merge fa3f939ed into c529ad924
Pull Request #7077: feat: add burnchain DB copy and validation

3654 of 4220 new or added lines in 18 files covered. (86.59%)

19324 existing lines in 182 files now uncovered.

171991 of 221755 relevant lines covered (77.56%)

7658447.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/stacks-node/src/monitoring/prometheus.rs
1
use async_std::net::{TcpListener, TcpStream};
2
use async_std::prelude::*;
3
use async_std::task;
4
use http_types::{Body, Response, StatusCode};
5
use stacks::prometheus::{gather, Encoder, TextEncoder};
6

7
use super::MonitoringError;
8

UNCOV
9
pub fn start_serving_prometheus_metrics(bind_address: String) -> Result<(), MonitoringError> {
×
UNCOV
10
    task::block_on(async {
×
UNCOV
11
        let listener = TcpListener::bind(bind_address)
×
UNCOV
12
            .await
×
UNCOV
13
            .map_err(|_| {
×
UNCOV
14
                warn!("Prometheus monitoring: unable to bind address, will not spawn prometheus endpoint service.");
×
UNCOV
15
                MonitoringError::AlreadyBound
×
UNCOV
16
            })?;
×
UNCOV
17
        let local_addr = listener
×
UNCOV
18
                .local_addr()
×
UNCOV
19
                .map_err(|_| {
×
20
                    warn!("Prometheus monitoring: unable to get local bind address, will not spawn prometheus endpoint service.");
×
21
                    MonitoringError::UnableToGetAddress
×
22
                })?;
×
UNCOV
23
        info!("Prometheus monitoring: server listening on http://{local_addr}");
×
24

UNCOV
25
        let mut incoming = listener.incoming();
×
UNCOV
26
        while let Some(stream) = incoming.next().await {
×
UNCOV
27
            let stream = match stream {
×
UNCOV
28
                Ok(stream) => stream,
×
29
                Err(err) => {
×
30
                    error!(
×
31
                        "Prometheus monitoring: unable to open socket and serve metrics - {err:?}",
32
                    );
33
                    continue;
×
34
                }
35
            };
UNCOV
36
            task::spawn(async {
×
UNCOV
37
                if let Err(err) = accept(stream).await {
×
38
                    error!("{err}");
×
UNCOV
39
                }
×
UNCOV
40
            });
×
41
        }
42

43
        Ok::<_, MonitoringError>(())
×
UNCOV
44
    })
×
UNCOV
45
}
×
46

UNCOV
47
async fn accept(stream: TcpStream) -> http_types::Result<()> {
×
UNCOV
48
    debug!("Handle Prometheus polling ({})", stream.peer_addr()?);
×
UNCOV
49
    async_h1::accept(stream.clone(), |_| async {
×
UNCOV
50
        let encoder = TextEncoder::new();
×
UNCOV
51
        let metric_families = gather();
×
UNCOV
52
        let mut buffer = vec![];
×
UNCOV
53
        encoder.encode(&metric_families, &mut buffer).unwrap();
×
54

UNCOV
55
        let mut response = Response::new(StatusCode::Ok);
×
UNCOV
56
        response.append_header("Content-Type", encoder.format_type());
×
UNCOV
57
        response.set_body(Body::from(buffer));
×
58

UNCOV
59
        Ok(response)
×
UNCOV
60
    })
×
UNCOV
61
    .await?;
×
UNCOV
62
    Ok(())
×
UNCOV
63
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc