Compare commits

..

No commits in common. "staging_test" and "main" have entirely different histories.

5 changed files with 1163 additions and 1538 deletions

794
Cargo.lock generated

File diff suppressed because it is too large Load diff

1817
Cargo.nix

File diff suppressed because it is too large Load diff

View file

@ -10,17 +10,17 @@
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1713199118,
"narHash": "sha256-MlLdAvk+zXCFUy280sY6LqtykqWXIkKVXo72J7a6HlU=",
"owner": "cargo2nix",
"lastModified": 1666087781,
"narHash": "sha256-trKVdjMZ8mNkGfLcY5LsJJGtdV3xJDZnMVrkFjErlcs=",
"owner": "Alexis211",
"repo": "cargo2nix",
"rev": "1efb03f2f794ad5eed17e807e858c4da001dbc3e",
"rev": "a7a61179b66054904ef6a195d8da736eaaa06c36",
"type": "github"
},
"original": {
"owner": "cargo2nix",
"owner": "Alexis211",
"repo": "cargo2nix",
"rev": "1efb03f2f794ad5eed17e807e858c4da001dbc3e",
"rev": "a7a61179b66054904ef6a195d8da736eaaa06c36",
"type": "github"
}
},
@ -60,11 +60,11 @@
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
@ -75,11 +75,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1714030708,
"narHash": "sha256-JOGPOxa8N6ySzB7SQBsh0OVz+UXZriyahgvfNHMIY0Y=",
"lastModified": 1696234590,
"narHash": "sha256-mgOzQYTvaTT4bFopVOadlndy2RPwLy60rDjIWOGujwo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b0d52b31f7f4d80f8bf38f0253652125579c35ff",
"rev": "f902cb49892d300ff15cb237e48aa1cad79d68c3",
"type": "github"
},
"original": {
@ -91,17 +91,17 @@
},
"nixpkgs_2": {
"locked": {
"lastModified": 1707091808,
"narHash": "sha256-LahKBAfGbY836gtpVNnWwBTIzN7yf/uYM/S0g393r0Y=",
"lastModified": 1665657542,
"narHash": "sha256-mojxNyzbvmp8NtVtxqiHGhRfjCALLfk9i/Uup68Y5q8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "9f2ee8c91ac42da3ae6c6a1d21555f283458247e",
"rev": "a3073c49bc0163fea6a121c276f526837672b555",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "9f2ee8c91ac42da3ae6c6a1d21555f283458247e",
"rev": "a3073c49bc0163fea6a121c276f526837672b555",
"type": "github"
}
},
@ -117,17 +117,16 @@
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1707271822,
"narHash": "sha256-/DZsoPH5GBzOpVEGz5PgJ7vh8Q6TcrJq5u8FcBjqAfI=",
"lastModified": 1682389182,
"narHash": "sha256-8t2nmFnH+8V48+IJsf8AK51ebXNlVbOSVYOpiqJKvJE=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "7a94fe7690d2bdfe1aab475382a505e14dc114a6",
"rev": "74f1a64dd28faeeb85ef081f32cad2989850322c",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "7a94fe7690d2bdfe1aab475382a505e14dc114a6",
"type": "github"
}
},

View file

@ -1,29 +1,22 @@
{
description = "Tricot, a reverse proxy with consul integration";
description = "A very basic flake";
# Nixpkgs 23.11 as of 2024-02-07, has rustc v1.73
inputs.nixpkgs.url =
"github:NixOS/nixpkgs/9f2ee8c91ac42da3ae6c6a1d21555f283458247e";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/a3073c49bc0163fea6a121c276f526837672b555";
inputs.cargo2nix = {
# cargo2nix as of 2024-04-25
url = "github:cargo2nix/cargo2nix/1efb03f2f794ad5eed17e807e858c4da001dbc3e";
# As of 2022-10-18: two small patches over unstable branch, one for clippy and one to fix feature detection
url = "github:Alexis211/cargo2nix/a7a61179b66054904ef6a195d8da736eaaa06c36";
# Rust overlay as of 2024-02-07
# Rust overlay as of 2023-04-25
inputs.rust-overlay.url =
"github:oxalica/rust-overlay/7a94fe7690d2bdfe1aab475382a505e14dc114a6";
"github:oxalica/rust-overlay/74f1a64dd28faeeb85ef081f32cad2989850322c";
inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, cargo2nix }:
let
targetHost = "x86_64-unknown-linux-musl";
pkgs = import nixpkgs {
system = "x86_64-linux";
crossSystem = {
config = targetHost;
isStatic = true;
};
overlays = [ cargo2nix.overlays.default ];
};
packageFun = import ./Cargo.nix;
@ -33,7 +26,6 @@
let
packageSet = pkgs.rustBuilder.makePackageSet ({
inherit packageFun rustVersion;
target = targetHost;
} // args);
in
packageSet.workspace.tricot {

View file

@ -41,21 +41,9 @@ pub struct HttpsConfig {
struct HttpsMetrics {
requests_received: metrics::Counter<u64>,
requests_served: metrics::Counter<u64>,
requests_in_flight: metrics::UpDownCounter<i64>,
request_proxy_duration: metrics::Histogram<f64>,
}
struct InFlightGuard<'a, 'b> {
metrics: &'a HttpsMetrics,
tags: &'b [KeyValue],
}
impl<'a, 'b> Drop for InFlightGuard<'a, 'b> {
fn drop(&mut self) {
self.metrics.requests_in_flight.add(-1, self.tags)
}
}
pub async fn serve_https(
config: HttpsConfig,
cert_store: Arc<CertStore>,
@ -74,10 +62,6 @@ pub async fn serve_https(
.u64_counter("https_requests_served")
.with_description("Total number of requests served over HTTPS")
.init(),
requests_in_flight: meter
.i64_up_down_counter("https_requests_in_flight")
.with_description("Current number of requests handled over HTTPS")
.init(),
request_proxy_duration: meter
.f64_histogram("https_request_proxy_duration")
.with_description("Duration between time when request was received, and time when backend returned status code and headers")
@ -194,7 +178,9 @@ async fn handle_request(
.unwrap_or_default(),
);
metrics.requests_received.add(1, &[host_tag, method_tag.clone()]);
metrics
.requests_received
.add(1, &[host_tag, method_tag.clone()]);
let mut tags = vec![method_tag];
let resp = select_target_and_proxy(
@ -286,17 +272,6 @@ async fn select_target_and_proxy(
);
proxy_to.calls_in_progress.fetch_add(1, Ordering::SeqCst);
let tags_in_flight = &tags.clone();
metrics.requests_in_flight.add(1, &tags_in_flight);
// The guard ensures that we decrement requests_in_flight in all cases where
// the current tasks ends, including the case where it gets canceled and
// doesn't run to completion (which may happen e.g. if it timeouts).
// (Crucially we create the guard before the first .await in this function.)
let _guard = InFlightGuard {
metrics: &metrics,
tags: &tags_in_flight,
};
// Forward to backend
debug!("{}{} -> {}", host, path, proxy_to);
trace!("Request: {:?}", req);