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

WIP: add regex replacements #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jcgruenhage
Copy link
Contributor

This allows users to specify a set of regexes that should be replaced in the path, to avoid having a gigantic set of metrics when the path contains resource IDs

@jcgruenhage jcgruenhage changed the title add regex replacements WIP: add regex replacements Sep 9, 2019
Copy link
Contributor Author

@jcgruenhage jcgruenhage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments

let mut path = String::from(path);
for (exp, repl) in self.replacements.clone() {
path = String::from(exp.replace_all(&path, &repl as &str))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really happy with this as it is, because each time we're updating metrics, we copy all replacements, the path once, and then the path again for each replacement. I couldn't find a way to do this with less copies though that also makes the borrow checker happy.


Ok((http_requests_total, http_requests_duration_seconds))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally a cfg attribute on the parameter would make duplicating this method unnecessary, but that would require rust nightly, since attributes on parameters are not stabilized yet (proposed to be stabilized soon though!)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's now in 1.39 so this can be changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It requires that we bump the minimum rust version to 1.39, if that's okay we can do that.

[dependencies]
actix-service = "0.4"
actix-web = "1.0.0"
futures = "0.1"
prometheus = "0.7"
regex = { version = "1.3.1", optional = true }
log = "0.4.8"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be more logging in this crate IMO, added the log crate to enable logging.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed.

@jcgruenhage
Copy link
Contributor Author

force push to rebase onto the new changes on master

@jcgruenhage
Copy link
Contributor Author

@nlopes this is marked as WIP because there is a bug in here somewhere. In the app I wrote this for, once switch from master to this version, for some endpoints metrics aren't recorded, and sometimes already recorded metrics also get lost and it all starts over, without any panics or errors in the logs. With the version from the master branch, it all works fine. Could you have a look?

Copy link
Owner

@nlopes nlopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a few tests overall. I'm also not yet 100% on this but I'm warming up to the idea.

On your concern about the bug, I personally couldn't find it through my experimentation with your branch - maybe tests will help?

Thanks for submitting this, I really appreciate it.


Ok((http_requests_total, http_requests_duration_seconds))
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's now in 1.39 so this can be changed.

@jcgruenhage
Copy link
Contributor Author

I'm currently occupied with deployments. Once I'm back from in dev land from my ops tasks, I'll update this with 1.39 in mind and try to reproduce the bug I was experiencing.

@nazar-pc
Copy link
Contributor

nazar-pc commented Jul 1, 2020

I believe #20 will make this mostly unnecessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants