Skip to content

Commit bb8ccd5

Browse files
committed
chore: change otel collector policies (#2436)
<!-- Please make sure there is an issue that this PR is correlated to. --> ## Changes <!-- If there are frontend changes, please include screenshots. -->
1 parent d450f12 commit bb8ccd5

File tree

4 files changed

+147
-65
lines changed

4 files changed

+147
-65
lines changed

packages/core/services/cluster/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ rivet-runtime.workspace = true
2525
s3-util.workspace = true
2626
serde = { version = "1.0.198", features = ["derive"] }
2727
serde_urlencoded = "0.7.0"
28+
serde_yaml = "0.9.34"
2829
ssh2 = "0.9.4"
2930
strum = { version = "0.24", features = ["derive"] }
3031
trust-dns-resolver = { version = "0.23.2", features = ["dns-over-native-tls"] }

packages/core/services/cluster/src/workflows/server/install/install_scripts/components/mod.rs

Lines changed: 142 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,153 @@ pub mod process_exporter {
3333
}
3434

3535
pub mod otel_collector {
36+
use chirp_workflow::prelude::*;
37+
use serde_json::json;
38+
3639
use super::traefik::TUNNEL_OTEL_PORT;
40+
use crate::types::PoolType;
3741

3842
const VERSION: &str = "0.125.0";
3943

40-
pub fn install() -> String {
41-
include_str!("../files/otel_collector.sh")
44+
pub fn install(pool_type: PoolType) -> GlobalResult<String> {
45+
let config = json!({
46+
"receivers": {
47+
"otlp": {
48+
"protocols": {
49+
"grpc": {
50+
"endpoint": "0.0.0.0:4317"
51+
},
52+
"http": {
53+
"endpoint": "0.0.0.0:4318"
54+
}
55+
}
56+
}
57+
},
58+
"processors": {
59+
"batch": {
60+
"timeout": "5s",
61+
"send_batch_size": 10000
62+
},
63+
"tail_sampling": {
64+
"decision_wait": "60s",
65+
"num_traces": 50000,
66+
"expected_new_traces_per_sec": 10,
67+
"decision_cache": {
68+
"sampled_cache_size": 1000,
69+
"non_sampled_cache_size": 1000
70+
},
71+
"policies": if let PoolType::Guard = pool_type {
72+
json!([
73+
{
74+
"name": "policy-1",
75+
"type": "and",
76+
"and": {
77+
"and_sub_policy": [
78+
{
79+
"name": "and-policy-1",
80+
"type": "status_code",
81+
"status_code": {
82+
"status_codes": [
83+
"ERROR"
84+
]
85+
}
86+
},
87+
{
88+
"name": "and-policy-2",
89+
"type": "probabilistic",
90+
"probabilistic": {
91+
"sampling_percentage": 10
92+
}
93+
}
94+
]
95+
}
96+
},
97+
{
98+
"name": "policy-2",
99+
"type": "ottl_condition",
100+
"ottl_condition": {
101+
"span": [
102+
"name == \"subscribe\" and attributes[\"message\"] == \"pegboard_actor_ready\""
103+
]
104+
}
105+
}
106+
])
107+
} else {
108+
json!([
109+
{
110+
"name": "policy-1",
111+
"type": "status_code",
112+
"status_code": {
113+
"status_codes": [
114+
"ERROR"
115+
]
116+
}
117+
},
118+
{
119+
"name": "policy-2",
120+
"type": "ottl_condition",
121+
"ottl_condition": {
122+
"span": [
123+
"name == \"message\" and attributes[\"message\"] == \"pegboard_actor_ready\""
124+
]
125+
}
126+
}
127+
])
128+
}
129+
}
130+
},
131+
"exporters": {
132+
"otlp": {
133+
"endpoint": format!("127.0.0.1:{TUNNEL_OTEL_PORT}"),
134+
"tls": {
135+
"insecure": true
136+
}
137+
}
138+
},
139+
"service": {
140+
"pipelines": {
141+
"logs": {
142+
"receivers": [
143+
"otlp"
144+
],
145+
"processors": [
146+
"batch"
147+
],
148+
"exporters": [
149+
"otlp"
150+
]
151+
},
152+
"traces": {
153+
"receivers": [
154+
"otlp"
155+
],
156+
"processors": [
157+
"tail_sampling",
158+
"batch"
159+
],
160+
"exporters": [
161+
"otlp"
162+
]
163+
},
164+
"metrics": {
165+
"receivers": [
166+
"otlp"
167+
],
168+
"processors": [
169+
"batch"
170+
],
171+
"exporters": [
172+
"otlp"
173+
]
174+
}
175+
}
176+
}
177+
});
178+
let config = serde_yaml::to_string(&config)?;
179+
180+
Ok(include_str!("../files/otel_collector.sh")
42181
.replace("__VERSION__", VERSION)
43-
.replace("__TUNNEL_OTEL_PORT__", &TUNNEL_OTEL_PORT.to_string())
182+
.replace("__CONFIG__", &config))
44183
}
45184
}
46185

packages/core/services/cluster/src/workflows/server/install/install_scripts/files/otel_collector.sh

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,65 +14,7 @@ install -o otelcol -g otelcol "/opt/otelcol-__VERSION__/otelcol" /usr/bin/
1414

1515
# Write config
1616
cat << 'EOF' > /etc/otelcol/config.yaml
17-
receivers:
18-
otlp:
19-
protocols:
20-
grpc:
21-
endpoint: 0.0.0.0:4317
22-
http:
23-
endpoint: 0.0.0.0:4318
24-
25-
processors:
26-
batch:
27-
timeout: 5s
28-
send_batch_size: 10000
29-
tail_sampling:
30-
decision_wait: 60s
31-
num_traces: 50000
32-
expected_new_traces_per_sec: 10
33-
decision_cache:
34-
sampled_cache_size: 1000
35-
non_sampled_cache_size: 1000
36-
policies:
37-
- name: policy-1
38-
type: status_code
39-
status_code:
40-
status_codes:
41-
- ERROR
42-
# Guard-only policy
43-
- name: policy-2
44-
type: and
45-
and:
46-
and_sub_policy:
47-
- name: latency-policy-1
48-
type: latency
49-
latency:
50-
threshold_ms: 15000
51-
- name: span-name-policy-1
52-
type: ottl_condition
53-
ottl_condition:
54-
span:
55-
- 'name == "routing_fn"'
56-
exporters:
57-
otlp:
58-
endpoint: 127.0.0.1:__TUNNEL_OTEL_PORT__
59-
tls:
60-
insecure: true
61-
62-
service:
63-
pipelines:
64-
logs:
65-
receivers: [otlp]
66-
processors: [batch]
67-
exporters: [otlp]
68-
traces:
69-
receivers: [otlp]
70-
processors: [tail_sampling, batch]
71-
exporters: [otlp]
72-
metrics:
73-
receivers: [otlp]
74-
processors: [batch]
75-
exporters: [otlp]
17+
__CONFIG__
7618
EOF
7719

7820
# Change owner

packages/core/services/cluster/src/workflows/server/install/install_scripts/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub async fn gen_install(
5353
}
5454
PoolType::Pegboard | PoolType::PegboardIsolate => {
5555
script.push(components::docker::install());
56-
script.push(components::otel_collector::install());
56+
script.push(components::otel_collector::install(pool_type)?);
5757
script.push(components::lz4::install());
5858
script.push(components::skopeo::install());
5959
script.push(components::umoci::install());
@@ -72,15 +72,15 @@ pub async fn gen_install(
7272
script.push(components::fdb::install(initialize_immediately));
7373
}
7474
PoolType::Worker => {
75-
script.push(components::otel_collector::install());
75+
script.push(components::otel_collector::install(pool_type)?);
7676
script.push(components::rivet::worker::install(config)?);
7777
}
7878
PoolType::Nats => {
7979
script.push(components::docker::install());
8080
script.push(components::nats::install(config)?);
8181
}
8282
PoolType::Guard => {
83-
script.push(components::otel_collector::install());
83+
script.push(components::otel_collector::install(pool_type)?);
8484
script.push(components::ok_server::install(initialize_immediately));
8585
script.push(components::rivet::guard::install(config)?);
8686
}

0 commit comments

Comments
 (0)