generated from Patagia/template-nix
Compare commits
1 commit
add9df8f87
...
3981b24d3d
Author | SHA1 | Date | |
---|---|---|---|
3981b24d3d |
13 changed files with 64 additions and 104 deletions
|
@ -1,8 +1,4 @@
|
|||
nix_direnv_manual_reload
|
||||
use flake
|
||||
export DATABASE_URL=postgresql://patagia:swordfish@patagia?host=$XDG_RUNTIME_DIR/patagia-postgres
|
||||
export OTEL_EXPORTER_OTLP_TRACES_PROTOCOL="http/protobuf"
|
||||
export OTEL_RESOURCE_ATTRIBUTES=host.name=$HOSTNAME
|
||||
export OTEL_SERVICE_NAME=$USER.patagia-control
|
||||
export OTEL_TRACES_SAMPLER=always_on
|
||||
export DATABASE_URL=postgresql://patagia:swordfish@/patagia?host=$XDG_RUNTIME_DIR/patagia-postgres
|
||||
dotenv_if_exists
|
||||
|
|
37
Cargo.lock
generated
37
Cargo.lock
generated
|
@ -1173,15 +1173,13 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "instrumentation"
|
||||
version = "0.2.0"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"http",
|
||||
"once_cell",
|
||||
"opentelemetry",
|
||||
"opentelemetry-appender-tracing",
|
||||
"opentelemetry-otlp",
|
||||
"opentelemetry-resource-detectors",
|
||||
"opentelemetry-semantic-conventions",
|
||||
"opentelemetry_sdk",
|
||||
"tonic",
|
||||
|
@ -1510,20 +1508,6 @@ dependencies = [
|
|||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "opentelemetry-appender-tracing"
|
||||
version = "0.27.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab5feffc321035ad94088a7e5333abb4d84a8726e54a802e736ce9dd7237e85b"
|
||||
dependencies = [
|
||||
"log",
|
||||
"opentelemetry",
|
||||
"tracing",
|
||||
"tracing-core",
|
||||
"tracing-log",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "opentelemetry-otlp"
|
||||
version = "0.27.0"
|
||||
|
@ -1555,17 +1539,6 @@ dependencies = [
|
|||
"tonic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "opentelemetry-resource-detectors"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf6e83d3dca8fe93cfac95cd07313721c9e6e9f8655e7b06d061d4924df1a0cd"
|
||||
dependencies = [
|
||||
"opentelemetry",
|
||||
"opentelemetry-semantic-conventions",
|
||||
"opentelemetry_sdk",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "opentelemetry-semantic-conventions"
|
||||
version = "0.27.0"
|
||||
|
@ -1630,7 +1603,7 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
|||
|
||||
[[package]]
|
||||
name = "patagia-agent"
|
||||
version = "0.2.0"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
|
@ -1648,7 +1621,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "patagia-controller"
|
||||
version = "0.2.0"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
|
@ -2925,7 +2898,7 @@ checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
|
|||
|
||||
[[package]]
|
||||
name = "trace-request"
|
||||
version = "0.2.0"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"dropshot",
|
||||
"http",
|
||||
|
@ -3532,7 +3505,7 @@ checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51"
|
|||
|
||||
[[package]]
|
||||
name = "xtask"
|
||||
version = "0.2.0"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
|
|
15
Cargo.toml
15
Cargo.toml
|
@ -27,13 +27,18 @@ anyhow = "1.0.95"
|
|||
clap = { version = "4.5.23", features = [
|
||||
"derive",
|
||||
"deprecated",
|
||||
"env",
|
||||
"wrap_help",
|
||||
"string",
|
||||
] }
|
||||
dropshot = "0.15.1"
|
||||
http = "1.2.0"
|
||||
once_cell = "1.20.2"
|
||||
opentelemetry = "0.27.1"
|
||||
opentelemetry-appender-tracing = { version = "0.27.0", features = ["log", "experimental_metadata_attributes"] }
|
||||
opentelemetry-otlp = { version = "0.27.0", features = ["grpc-tonic", "gzip-tonic", "zstd-tonic", "tls", "tls-roots", "trace"] }
|
||||
opentelemetry_sdk = { version = "0.27.1", features = ["metrics", "rt-tokio"] }
|
||||
opentelemetry-semantic-conventions = "0.27.0"
|
||||
opentelemetry-stdout = "0.27.0"
|
||||
progenitor = "0.8.0"
|
||||
reqwest = { version = "0.12.12", features = ["json", "stream", "rustls-tls"] }
|
||||
schemars = "0.8.21"
|
||||
|
@ -42,8 +47,16 @@ serde = { version = "1.0.217", features = ["derive"] }
|
|||
slog = "2.7.0"
|
||||
slog-async = "2.8.0"
|
||||
tokio = { version = "1.42.0", features = ["full"] }
|
||||
tonic = "0.12.3"
|
||||
tracing = "0.1.41"
|
||||
tracing-core = "0.1.33"
|
||||
tracing-chrome = "0.7.2"
|
||||
tracing-opentelemetry = "0.28.0"
|
||||
tracing-slog = { git = "https://github.com/oxidecomputer/tracing-slog", default-features = false }
|
||||
tracing-subscriber = { version = "0.3.19", default-features = false, features = [
|
||||
"std",
|
||||
"ansi",
|
||||
"env-filter",
|
||||
"fmt",
|
||||
] }
|
||||
uuid = { version = "1", features = [ "serde", "v4" ] }
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
[package]
|
||||
name = "patagia-agent"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "MPL-2.0"
|
||||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
|
|
|
@ -163,6 +163,7 @@ pub struct Describe_Reply {
|
|||
impl varlink::VarlinkReply for Describe_Reply {}
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct Describe_Args {}
|
||||
#[allow(dead_code)]
|
||||
pub trait Call_Describe: VarlinkCallError {
|
||||
fn reply(
|
||||
&mut self,
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use crate::io_systemd_Hostname::VarlinkClientInterface;
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use tokio::time::{sleep, Duration};
|
||||
use varlink::Connection;
|
||||
use io_systemd_Hostname::VarlinkClientInterface;
|
||||
|
||||
mod io_systemd_Hostname;
|
||||
mod patagia_api;
|
||||
mod io_systemd_Hostname;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
|
@ -37,15 +37,11 @@ async fn main() -> Result<()> {
|
|||
let mut systemd_hostname_iface = io_systemd_Hostname::VarlinkClient::new(conn);
|
||||
|
||||
let desc = systemd_hostname_iface.describe().call()?;
|
||||
println!(
|
||||
"Welcome {} (Machine ID: {})!",
|
||||
desc.Hostname, desc.MachineID
|
||||
);
|
||||
println!("Welcome {} (Machine ID: {})!", desc.Hostname, desc.MachineID);
|
||||
|
||||
let client = patagia_api::Client::new("http://localhost:9474");
|
||||
let result = client.version().await?;
|
||||
tracing::info!("Result: {:?}", result);
|
||||
tracing::info!("Patagia Agent finished");
|
||||
|
||||
sleep(Duration::from_secs(3)).await;
|
||||
Ok(())
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
[package]
|
||||
name = "patagia-controller"
|
||||
description = "Patagia control plane server"
|
||||
description = "Patagia controller server"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "MPL-2.0"
|
||||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
|
|
|
@ -18,7 +18,7 @@ struct Cli {
|
|||
#[arg(
|
||||
long = "telemetry-otlp-endpoint",
|
||||
default_value = "http://localhost:4317",
|
||||
env = "OTEL_EXPORTER_OTLP_ENDPOINT"
|
||||
value_name = "OTEL_EXPORTER_OTLP_ENDPOINT"
|
||||
)]
|
||||
otlp_endpoint: Option<String>,
|
||||
|
||||
|
@ -26,16 +26,9 @@ struct Cli {
|
|||
long = "log-stderr",
|
||||
short = 'v',
|
||||
default_value = "false",
|
||||
env = "LOG_TO_STDERR"
|
||||
value_name = "LOG_TO_STDERR"
|
||||
)]
|
||||
log_stderr: bool,
|
||||
|
||||
#[arg(
|
||||
long = "listen-address",
|
||||
default_value = "0.0.0.0:9474",
|
||||
env = "LISTEN_ADDRESS"
|
||||
)]
|
||||
listen_address: String,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
@ -46,7 +39,7 @@ async fn main() -> Result<()> {
|
|||
tracing::info!("Patagia Controller");
|
||||
|
||||
let config = ConfigDropshot {
|
||||
bind_address: SocketAddr::from_str(&args.listen_address).unwrap(),
|
||||
bind_address: SocketAddr::from_str("0.0.0.0:9474").unwrap(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
|
|
@ -1,24 +1,17 @@
|
|||
[package]
|
||||
name = "instrumentation"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "MPL-2.0"
|
||||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
http.workspace = true
|
||||
once_cell.workspace = true
|
||||
opentelemetry-otlp = { version = "0.27.0", features = ["grpc-tonic", "gzip-tonic", "zstd-tonic", "tls", "tls-roots", "trace"] }
|
||||
opentelemetry_sdk = { version = "0.27.1", features = ["metrics", "rt-tokio"] }
|
||||
opentelemetry-semantic-conventions = "0.27.0"
|
||||
opentelemetry-appender-tracing = { version = "0.27.0", features = ["log", "experimental_metadata_attributes"] }
|
||||
opentelemetry-resource-detectors = { version = "0.6.0" }
|
||||
opentelemetry = "0.27.1"
|
||||
tonic = "0.12.3"
|
||||
tracing-opentelemetry = "0.28.0"
|
||||
tracing-subscriber = { version = "0.3.19", default-features = false, features = [
|
||||
"std",
|
||||
"ansi",
|
||||
"env-filter",
|
||||
"fmt",
|
||||
] }
|
||||
opentelemetry-otlp.workspace = true
|
||||
opentelemetry_sdk.workspace = true
|
||||
opentelemetry-semantic-conventions.workspace = true
|
||||
opentelemetry.workspace = true
|
||||
tonic.workspace = true
|
||||
tracing-opentelemetry.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use anyhow::{anyhow, Result};
|
||||
use once_cell::sync::Lazy;
|
||||
use opentelemetry::{trace::TracerProvider as _, KeyValue};
|
||||
use opentelemetry_otlp::{WithExportConfig, WithTonicConfig};
|
||||
use opentelemetry_sdk::{
|
||||
|
@ -8,15 +9,25 @@ use opentelemetry_sdk::{
|
|||
trace::{RandomIdGenerator, Sampler, TracerProvider},
|
||||
Resource,
|
||||
};
|
||||
use opentelemetry_semantic_conventions as semcov;
|
||||
use tracing_opentelemetry::{MetricsLayer, OpenTelemetryLayer};
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
|
||||
use std::time::Duration;
|
||||
static RESOURCE: Lazy<Resource> = Lazy::new(|| {
|
||||
Resource::new(vec![
|
||||
KeyValue::new(
|
||||
opentelemetry_semantic_conventions::resource::SERVICE_NAME,
|
||||
env!("CARGO_PKG_NAME"),
|
||||
),
|
||||
KeyValue::new(
|
||||
opentelemetry_semantic_conventions::resource::SERVICE_VERSION,
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
),
|
||||
])
|
||||
});
|
||||
|
||||
// Construct MeterProvider for MetricsLayer
|
||||
fn init_meter_provider(otel_endpoint: &String, resource: Resource) -> Result<SdkMeterProvider> {
|
||||
fn init_meter_provider(otel_endpoint: &String) -> Result<SdkMeterProvider> {
|
||||
let exporter = opentelemetry_otlp::MetricExporter::builder()
|
||||
.with_tonic()
|
||||
.with_endpoint(otel_endpoint)
|
||||
|
@ -27,7 +38,7 @@ fn init_meter_provider(otel_endpoint: &String, resource: Resource) -> Result<Sdk
|
|||
.map_err(|e| anyhow!("Error creating OTLP metric exporter: {:?}", e))?;
|
||||
|
||||
let meter_provider = MeterProviderBuilder::default()
|
||||
.with_resource(resource)
|
||||
.with_resource(RESOURCE.clone())
|
||||
.with_reader(
|
||||
PeriodicReader::builder(exporter, runtime::Tokio)
|
||||
.with_interval(std::time::Duration::from_secs(10))
|
||||
|
@ -41,7 +52,7 @@ fn init_meter_provider(otel_endpoint: &String, resource: Resource) -> Result<Sdk
|
|||
}
|
||||
|
||||
// Construct TracerProvider for OpenTelemetryLayer
|
||||
fn init_tracer_provider(otel_endpoint: &String, resource: Resource) -> Result<TracerProvider> {
|
||||
fn init_tracer_provider(otel_endpoint: &String) -> Result<TracerProvider> {
|
||||
let exporter = opentelemetry_otlp::SpanExporter::builder()
|
||||
.with_tonic()
|
||||
.with_tls_config(tonic::transport::ClientTlsConfig::new().with_native_roots())
|
||||
|
@ -54,7 +65,7 @@ fn init_tracer_provider(otel_endpoint: &String, resource: Resource) -> Result<Tr
|
|||
.with_sampler(Sampler::ParentBased(Box::new(Sampler::TraceIdRatioBased(
|
||||
1.0,
|
||||
))))
|
||||
.with_resource(resource)
|
||||
.with_resource(RESOURCE.clone())
|
||||
.with_id_generator(RandomIdGenerator::default())
|
||||
.with_batch_exporter(exporter, opentelemetry_sdk::runtime::Tokio)
|
||||
.build();
|
||||
|
@ -64,25 +75,6 @@ fn init_tracer_provider(otel_endpoint: &String, resource: Resource) -> Result<Tr
|
|||
|
||||
// Initialize tracing-subscriber and return TracingGuard for opentelemetry-related termination processing
|
||||
pub fn init_tracing(otel_endpoint: Option<&String>, log_stderr: bool) -> Result<TracingGuard> {
|
||||
let resource = {
|
||||
let r = Resource::new([KeyValue::new(
|
||||
semcov::resource::SERVICE_VERSION,
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
)]);
|
||||
|
||||
let detected = Resource::from_detectors(
|
||||
Duration::from_secs(5),
|
||||
vec![
|
||||
Box::new(opentelemetry_sdk::resource::SdkProvidedResourceDetector),
|
||||
Box::new(opentelemetry_sdk::resource::EnvResourceDetector::new()),
|
||||
Box::new(opentelemetry_resource_detectors::OsResourceDetector),
|
||||
Box::new(opentelemetry_resource_detectors::ProcessResourceDetector),
|
||||
Box::new(opentelemetry_sdk::resource::TelemetryResourceDetector),
|
||||
],
|
||||
);
|
||||
r.merge(&detected)
|
||||
};
|
||||
|
||||
let env_filter = tracing_subscriber::EnvFilter::try_from_default_env()
|
||||
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new(""));
|
||||
|
||||
|
@ -92,7 +84,7 @@ pub fn init_tracing(otel_endpoint: Option<&String>, log_stderr: bool) -> Result<
|
|||
};
|
||||
|
||||
let meter_provider = match otel_endpoint {
|
||||
Some(endpoint) => Some(init_meter_provider(endpoint, resource.clone())?),
|
||||
Some(endpoint) => Some(init_meter_provider(endpoint)?),
|
||||
None => None,
|
||||
};
|
||||
|
||||
|
@ -102,7 +94,7 @@ pub fn init_tracing(otel_endpoint: Option<&String>, log_stderr: bool) -> Result<
|
|||
};
|
||||
|
||||
let tracer_provider = match otel_endpoint {
|
||||
Some(endpoint) => Some(init_tracer_provider(endpoint, resource)?),
|
||||
Some(endpoint) => Some(init_tracer_provider(endpoint)?),
|
||||
None => None,
|
||||
};
|
||||
|
||||
|
|
7
justfile
7
justfile
|
@ -57,7 +57,7 @@ check-nix:
|
|||
|
||||
# Run PostgreSQL for development and testing
|
||||
dev-postgres:
|
||||
mkdir -p "${XDG_RUNTIME_DIR}/patagia-postgres"
|
||||
mkdir -p "$XDG_RUNTIME_DIR/patagia-postgres"
|
||||
podman volume exists patagia-postgres || podman volume create patagia-postgres
|
||||
podman run \
|
||||
--detach \
|
||||
|
@ -67,9 +67,12 @@ dev-postgres:
|
|||
--env POSTGRES_USER=patagia \
|
||||
--env POSTGRES_PASSWORD=swordfish \
|
||||
--volume patagia-postgres:/var/lib/postgresql/data \
|
||||
--volume "${XDG_RUNTIME_DIR}/patagia-postgres:/var/run/postgresql" \
|
||||
--volume "$XDG_RUNTIME_DIR/patagia-postgres:/var/run/postgresql" \
|
||||
docker.io/postgres:17
|
||||
|
||||
# Reset PostgreSQL data and start
|
||||
dev-postgres-reset: dev-postgres-clean dev-postgres
|
||||
|
||||
# Clean up PostgreSQL data
|
||||
dev-postgres-clean:
|
||||
podman rm -f patagia-postgres || true
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
[package]
|
||||
name = "trace-request"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "MPL-2.0"
|
||||
version.workspace = true
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "xtask"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
version.workspace = true
|
||||
|
||||
[[bin]]
|
||||
name = "xtask"
|
||||
|
|
Loading…
Add table
Reference in a new issue