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

Fix duplicate metric labels #518

Merged
merged 2 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions rust/abacus-base/src/contract_sync/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ impl ContractSyncMetrics {
.new_int_gauge(
"contract_sync_block_height",
"Height of a recently observed block",
&["data_type", "contract_name", "agent"],
&["data_type", "contract_name"],
)
.expect("failed to register block_height metric");

let stored_events = metrics
.new_int_gauge(
"contract_sync_stored_events",
"Number of events stored into db",
&["data_type", "contract_name", "agent"],
&["data_type", "contract_name"],
)
.expect("failed to register stored_events metric");

let missed_events = metrics
.new_int_counter(
"contract_sync_missed_events",
"Number of unique occasions when agent missed an event",
&["data_type", "contract_name", "agent"],
&["data_type", "contract_name"],
)
.expect("failed to register missed_events metric");

Expand Down
39 changes: 17 additions & 22 deletions rust/abacus-base/src/contract_sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const MESSAGES_LABEL: &str = "messages";
/// db up-to-date.
#[derive(Debug)]
pub struct ContractSync<I> {
agent_name: String,
contract_name: String,
db: AbacusDB,
indexer: Arc<I>,
Expand All @@ -41,15 +40,13 @@ pub struct ContractSync<I> {
impl<I> ContractSync<I> {
/// Instantiate new ContractSync
pub fn new(
agent_name: String,
contract_name: String,
db: AbacusDB,
indexer: Arc<I>,
index_settings: IndexSettings,
metrics: ContractSyncMetrics,
) -> Self {
Self {
agent_name,
contract_name,
db,
indexer,
Expand Down Expand Up @@ -86,23 +83,23 @@ where

let db = self.db.clone();
let indexer = self.indexer.clone();
let indexed_height = self.metrics.indexed_height.clone().with_label_values(&[
MESSAGES_LABEL,
&self.contract_name,
&self.agent_name,
]);

let stored_messages = self.metrics.stored_events.clone().with_label_values(&[
MESSAGES_LABEL,
&self.contract_name,
&self.agent_name,
]);

let missed_messages = self.metrics.missed_events.clone().with_label_values(&[
MESSAGES_LABEL,
&self.contract_name,
&self.agent_name,
]);
let indexed_height = self
.metrics
.indexed_height
.clone()
.with_label_values(&[MESSAGES_LABEL, &self.contract_name]);

let stored_messages = self
.metrics
.stored_events
.clone()
.with_label_values(&[MESSAGES_LABEL, &self.contract_name]);

let missed_messages = self
.metrics
.missed_events
.clone()
.with_label_values(&[MESSAGES_LABEL, &self.contract_name]);

let message_leaf_index = self.metrics.message_leaf_index.clone();

Expand Down Expand Up @@ -519,7 +516,6 @@ mod test {
let sync_metrics = ContractSyncMetrics::new(metrics, None);

let contract_sync = ContractSync::new(
"agent".to_owned(),
"outbox_1".to_owned(),
abacus_db.clone(),
indexer.clone(),
Expand Down Expand Up @@ -822,7 +818,6 @@ mod test {
let sync_metrics = ContractSyncMetrics::new(metrics, None);

let contract_sync = ContractSync::new(
"agent".to_owned(),
"outbox_1".to_owned(),
abacus_db.clone(),
indexer.clone(),
Expand Down
2 changes: 0 additions & 2 deletions rust/abacus-base/src/inbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@ impl CachingInbox {
/// data
pub fn sync(
&self,
agent_name: String,
index_settings: IndexSettings,
metrics: ContractSyncMetrics,
) -> Instrumented<JoinHandle<Result<()>>> {
let span = info_span!("InboxContractSync", self = %self);

let sync = ContractSync::new(
agent_name,
String::from_str(self.inbox.name()).expect("!string"),
self.db.clone(),
self.indexer.clone(),
Expand Down
2 changes: 0 additions & 2 deletions rust/abacus-base/src/outbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@ impl CachingOutbox {
/// data
pub fn sync(
&self,
agent_name: String,
index_settings: IndexSettings,
metrics: ContractSyncMetrics,
) -> Instrumented<JoinHandle<Result<()>>> {
let span = info_span!("OutboxContractSync", self = %self);

let sync = ContractSync::new(
agent_name,
String::from_str(self.outbox.name()).expect("!string"),
self.db.clone(),
self.indexer.clone(),
Expand Down
8 changes: 3 additions & 5 deletions rust/agents/relayer/src/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,9 @@ impl Relayer {
let outbox_name = outbox.name();
let sync_metrics =
ContractSyncMetrics::new(self.metrics(), Some(&["dispatch", outbox_name, "unknown"]));
let sync = self.outbox().sync(
Self::AGENT_NAME.to_string(),
self.as_ref().indexer.clone(),
sync_metrics,
);
let sync = self
.outbox()
.sync(self.as_ref().indexer.clone(), sync_metrics);
sync
}

Expand Down