Skip to content

Commit

Permalink
[telemetry] enable metrics and on networkpolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
rustielin authored and aptos-bot committed May 13, 2022
1 parent e2954b4 commit c6c1d06
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 17 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/aptos-telemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ publish = false
edition = "2018"

[dependencies]
once_cell = "1.10.0"
reqwest = { version = "0.11.10", features = ["json"] }
serde = { version = "1.0.137", features = ["derive"], default-features = false }
serde_json = "1.0.81"
Expand Down
6 changes: 4 additions & 2 deletions crates/aptos-telemetry/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
pub const APTOS_GA_MEASUREMENT_ID: &str = "G-ZX4L6WPCFZ";
pub const APTOS_GA_API_SECRET: &str = "ArtslKPTTjeiMi1n-IR39g";

pub const HTTPBIN_URL: &str = "http://httpbin.org/ip";
pub const GA4_URL: &str = "http://www.google-analytics.com/mp/collect";
pub const HTTPBIN_URL: &str = "https://httpbin.org/ip";
// measurement protocol requires HTTPS
// https://developers.google.com/analytics/devguides/collection/protocol/v1/reference#transport
pub const GA4_URL: &str = "https://www.google-analytics.com/mp/collect";

// Timeouts
pub const NETWORK_PUSH_TIME_SECS: u64 = 30;
Expand Down
52 changes: 48 additions & 4 deletions crates/aptos-telemetry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
pub mod constants;

use aptos_logger::prelude::*;
use aptos_metrics::json_metrics::get_git_rev;
use aptos_metrics::{json_metrics::get_git_rev, register_int_counter_vec, IntCounterVec};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
Expand All @@ -20,6 +21,24 @@ pub const GA_MEASUREMENT_ID: &str = "GA_MEASUREMENT_ID";
pub const GA_API_SECRET: &str = "GA_API_SECRET";
pub const APTOS_TELEMETRY_DISABLE: &str = "APTOS_TELEMETRY_DISABLE";

pub static APTOS_TELEMETRY_SUCCESS: Lazy<IntCounterVec> = Lazy::new(|| {
register_int_counter_vec!(
"aptos_telemetry_success",
"Number of telemetry events successfully sent",
&["event_name"]
)
.unwrap()
});

pub static APTOS_TELEMETRY_FAILURE: Lazy<IntCounterVec> = Lazy::new(|| {
register_int_counter_vec!(
"aptos_telemetry_failure",
"Number of telemetry events failed to send",
&["event_name"]
)
.unwrap()
});

#[derive(Debug, Serialize, Deserialize)]
struct MetricsDump {
client_id: String,
Expand Down Expand Up @@ -86,7 +105,7 @@ pub async fn send_data(event_name: String, user_id: String, event_params: HashMa
.unwrap_or_else(|_| constants::APTOS_GA_MEASUREMENT_ID.to_string());

let metrics_event = MetricsEvent {
name: event_name,
name: event_name.clone(),
params: event_params,
};

Expand Down Expand Up @@ -114,8 +133,33 @@ pub async fn send_data(event_name: String, user_id: String, event_params: HashMa
.send()
.await;
match res {
Ok(_) => debug!("Sent telemetry data {:?}", &metrics_dump),
Err(e) => debug!("{:?}", e),
Ok(res) => {
let status_code = res.status().as_u16();
if status_code > 200 && status_code < 299 {
info!("Sent telemetry event {}", event_name.as_str());
debug!("Sent telemetry data {:?}", &metrics_dump);
APTOS_TELEMETRY_SUCCESS
.with_label_values(&[event_name.as_str()])
.inc();
} else {
info!(
"Failed to send telemetry event {}: {}",
res.status(),
event_name.as_str()
);
debug!("{:?}", res.text().await);
APTOS_TELEMETRY_FAILURE
.with_label_values(&[event_name.as_str()])
.inc();
}
}
Err(e) => {
info!("Failed to send telemetry event {}", event_name.as_str());
debug!("{:?}", e);
APTOS_TELEMETRY_FAILURE
.with_label_values(&[event_name.as_str()])
.inc();
}
}
});
}
2 changes: 1 addition & 1 deletion docker/faucet/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN IMAGE_TARGETS="test" ./docker/build-common.sh
### Production Image ###
FROM debian-base AS pre-test

RUN apt-get update && apt-get install -y libssl1.1 nano net-tools tcpdump iproute2 netcat \
RUN apt-get update && apt-get install -y libssl1.1 ca-certificates nano net-tools tcpdump iproute2 netcat \
&& apt-get clean && rm -r /var/lib/apt/lists/*

RUN mkdir -p /opt/aptos/bin /aptos/client/data/wallet/
Expand Down
2 changes: 1 addition & 1 deletion docker/forge/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN IMAGE_TARGETS="test" ./docker/build-common.sh

FROM debian-base

RUN apt-get update && apt-get install -y libssl1.1 openssh-client wget busybox git unzip awscli && apt-get clean && rm -r /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y libssl1.1 ca-certificates openssh-client wget busybox git unzip awscli && apt-get clean && rm -r /var/lib/apt/lists/*

RUN mkdir /aptos
COPY rust-toolchain /aptos/rust-toolchain
Expand Down
2 changes: 1 addition & 1 deletion docker/indexer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN IMAGE_TARGETS="release" ./docker/build-common.sh
### Production Image ###
FROM debian-base AS pre-prod

RUN apt-get update && apt-get install -y libssl1.1 net-tools tcpdump iproute2 netcat libpq-dev \
RUN apt-get update && apt-get install -y libssl1.1 ca-certificates net-tools tcpdump iproute2 netcat libpq-dev \
&& apt-get clean && rm -r /var/lib/apt/lists/*

RUN mkdir -p /opt/aptos/bin
Expand Down
2 changes: 1 addition & 1 deletion docker/init/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN IMAGE_TARGETS="release" ./docker/build-common.sh
### Production Image ###
FROM debian-base AS pre-prod

RUN apt-get update && apt-get -y install libssl1.1 wget busybox gettext-base && apt-get clean && rm -r /var/lib/apt/lists/*
RUN apt-get update && apt-get -y install libssl1.1 ca-certificates wget busybox gettext-base && apt-get clean && rm -r /var/lib/apt/lists/*
RUN cd /usr/local/bin && wget "https://storage.googleapis.com/kubernetes-release/release/v1.18.6/bin/linux/amd64/kubectl" -O kubectl && chmod +x kubectl
RUN cd /usr/local/bin && wget "https://releases.hashicorp.com/vault/1.5.0/vault_1.5.0_linux_amd64.zip" -O- | busybox unzip - && chmod +x vault

Expand Down
2 changes: 1 addition & 1 deletion docker/safety-rules/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN IMAGE_TARGETS="release" ./docker/build-common.sh
### Production Image ###
FROM debian-base AS prod

RUN apt-get update && apt-get install -y libssl1.1 && apt-get clean && rm -r /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y libssl1.1 ca-certificates && apt-get clean && rm -r /var/lib/apt/lists/*

RUN addgroup --system --gid 6180 aptos && adduser --system --ingroup aptos --no-create-home --uid 6180 aptos

Expand Down
2 changes: 1 addition & 1 deletion docker/txn-emitter/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN IMAGE_TARGETS="release" ./docker/build-common.sh
### Production Image ###
FROM debian-base AS pre-prod

RUN apt-get update && apt-get -y install libssl1.1 wget busybox gettext-base && apt-get clean && rm -r /var/lib/apt/lists/*
RUN apt-get update && apt-get -y install libssl1.1 ca-certificates wget busybox gettext-base && apt-get clean && rm -r /var/lib/apt/lists/*

RUN mkdir -p /opt/aptos/bin
COPY --from=builder /aptos/target/release/transaction-emitter /usr/local/bin
Expand Down
2 changes: 1 addition & 1 deletion docker/validator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN IMAGE_TARGETS="release" ./docker/build-common.sh
### Production Image ###
FROM debian-base AS prod

RUN apt-get update && apt-get install -y libssl1.1 && apt-get clean && rm -r /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y libssl1.1 ca-certificates && apt-get clean && rm -r /var/lib/apt/lists/*

### Needed to run debugging tools like perf
RUN apt-get update && apt-get install -y linux-tools-4.19 sudo procps
Expand Down
9 changes: 5 additions & 4 deletions terraform/helm/aptos-node/templates/validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,14 @@ spec:
- ports:
- protocol: TCP
port: 6180
# Aptos telemetry
- ports:
- protocol: TCP
port: 80
# DNS
- to:
- namespaceSelector: {}
ports:
- protocol: UDP
port: 53
# Enable HTTPS telemetry
- ports:
- protocol: TCP
port: 443

4 changes: 4 additions & 0 deletions terraform/helm/validator/templates/validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,7 @@ spec:
ports:
- protocol: UDP
port: 53
# Enable HTTPS telemetry
- ports:
- protocol: TCP
port: 443

0 comments on commit c6c1d06

Please sign in to comment.