Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds prometheus export point to the agent pod. #2983

Conversation

meowjesty
Copy link
Member

@meowjesty meowjesty commented Dec 17, 2024

@aviramha
Copy link
Member

Note - this should be behind a flag.

@meowjesty meowjesty marked this pull request as ready for review December 19, 2024 21:39
Copy link
Contributor

@Razz4780 Razz4780 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't go over the code in agent submodules yet, because I have an important request that might require changes there - please no new actor framework ;_;
You're already using axum router, so why not go with State? 👀
I'd just put all metrics in there (AtomicU64), wrap them together in Arc and share between the modules and the metrics endpoint

mirrord/agent/Cargo.toml Outdated Show resolved Hide resolved
mirrord/agent/README.md Outdated Show resolved Hide resolved
mirrord/agent/src/main.rs Outdated Show resolved Hide resolved
mirrord/kube/src/api/container/job.rs Outdated Show resolved Hide resolved
mirrord/kube/src/api/container/job.rs Outdated Show resolved Hide resolved
mirrord/kube/src/api/container/pod.rs Outdated Show resolved Hide resolved
mirrord/kube/src/api/container/pod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@Razz4780 Razz4780 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're missing:

  1. Stolen HTTP requests in progress
  2. Connected clients
  3. DNS lookups in progress

I see you went for global gauges, that's fine as well

mirrord/agent/src/entrypoint.rs Outdated Show resolved Hide resolved
mirrord/agent/src/entrypoint.rs Outdated Show resolved Hide resolved
mirrord/agent/src/file.rs Outdated Show resolved Hide resolved
mirrord/agent/src/metrics.rs Outdated Show resolved Hide resolved
mirrord/agent/src/metrics.rs Outdated Show resolved Hide resolved
mirrord/agent/src/steal/http/filter.rs Outdated Show resolved Hide resolved
mirrord/agent/src/steal/connection.rs Outdated Show resolved Hide resolved
mirrord/agent/src/metrics.rs Outdated Show resolved Hide resolved
mirrord/agent/src/metrics.rs Outdated Show resolved Hide resolved
mirrord/agent/src/metrics.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@Razz4780 Razz4780 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't like statics, you can go with sth like this:

#[derive(Clone)]
struct Metrics {
    open_file_descriptors: IntCounter,
    // other counters
}

// pass registry to the metrics http server
// pass metrics clones to agent tasks
fn setup_metrics_registry() -> (Registry, Metrics) {
    let open_file_descriptors = IntCounter::new("name", "help").unwrap();

    let registry = Registry::new();
    registry.register(Box::new(open_file_descriptors.clone())).unwrap();

    let metrics = Metrics {
        open_file_descriptors,
    };

    (registry, metrics)
}

// metrics endpoint handler
async fn get_metrics(State(registry): State<Registry>) -> (StatusCode, String) {
    let mut buffer = String::new();
    let encoder = TextEncoder::new();
    let metric_families = registry.gather();
    
    match encoder.encode_utf8(&metric_families, &mut buffer) {
        Ok(()) => (StatusCode::OK, buffer),
        Err(error) => {
            (StatusCode::INTERNAL_SERVER_ERROR, error.to_string())
        }
    }
}

// metrics http server router
async fn metrics_router(registry: Registry) -> Router {
    Router::new().route("/metrics", get(get_metrics)).with_state(registry)
}

Imho looks nicer and will allow for unit testing (statics would be shared across tests)

Copy link
Contributor

@Razz4780 Razz4780 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let this saga end

@meowjesty meowjesty requested a review from Razz4780 January 21, 2025 20:25
Copy link
Contributor

@Razz4780 Razz4780 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit for the new changes

mirrord/agent/src/metrics.rs Show resolved Hide resolved
Copy link
Contributor

@Razz4780 Razz4780 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The saga ends

@meowjesty meowjesty enabled auto-merge January 22, 2025 15:32
@meowjesty meowjesty added this pull request to the merge queue Jan 22, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jan 22, 2025
@meowjesty meowjesty enabled auto-merge January 22, 2025 18:01
@meowjesty meowjesty added this pull request to the merge queue Jan 22, 2025
Merged via the queue into metalbear-co:main with commit 57bdab5 Jan 22, 2025
17 checks passed
@meowjesty meowjesty deleted the meowchinist/mbe-578-add-prometheus-export-point-to-the-agent-pod branch January 22, 2025 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants