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

Updates handle_event/4 to extract latency metrics from a map #21

Merged
merged 2 commits into from Apr 24, 2019

Conversation

tzumby
Copy link
Contributor

@tzumby tzumby commented Apr 23, 2019

Fixes #19

The incoming latency parameter is a Map and this fix extracts the required metrics and adds them to the metadata map.

@deadtrickster deadtrickster merged commit 0646a1a into deadtrickster:master Apr 24, 2019
@deadtrickster
Copy link
Owner

Thanks!

@deadtrickster
Copy link
Owner

Maybe you also have some ecto3 tests to share :-)?

@@ -178,6 +178,15 @@ defmodule Prometheus.EctoInstrumenter do
end
end

def handle_event(_event, latency, metadata, _config) when is_map(latency) do
latency
|> Map.put(:decode_time, Map.get(latency, :decode_time, 0))
Copy link

@chulkilee chulkilee Apr 24, 2019

Choose a reason for hiding this comment

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

It can be done with Map.put_new(:decode_time, 0).

Please note that existing and my proposal both does handle when the key exists with nil value - in that case, it will remain as nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's definitely cleaner with put_new. Do we want to cover the case when it would be nil ? From what I can see the key is either present with a value or absent.

Choose a reason for hiding this comment

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

I don't know what will be passed in it - probably better to check the doc of code producing this.

However, I'd like to ask a question in different angle - why do we need to backfill missing :decode_time as 0? Wouldn`t it skew the stat, if it happens a lot?

I think it's better to pass as-is, and log/1 or other functions need to take care of missing:decode_time.

def handle_event(_event, latency, metadata, _config) when is_map(latency) do
latency
|> Map.put(:decode_time, Map.get(latency, :decode_time, 0))
|> Enum.reduce(metadata, fn {key, value}, metadata ->

Choose a reason for hiding this comment

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

What about using Map.merge/2? Then we need to change a little bit, as the current code use latency (first arg) over metadata map for duplicates, while Map.merge/2 uses the second arg.

metadata
|> Map.merge(Map.put_lazy(latency, :decode_time, 0))
|> log()

@tzumby
Copy link
Contributor Author

tzumby commented Apr 25, 2019

Thanks for merging this. I agree, this needs some test coverage. I'll try to get a PR in when I get a chance and include some of the suggestions from @chulkilee

@tzumby tzumby deleted the issue-9_bad_match_error branch April 25, 2019 20:26
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.

prometheus-ecto detached with badmatch error for ecto 3.1, telemetry 0.4.0
3 participants