-
Notifications
You must be signed in to change notification settings - Fork 67
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
Use Module for configuring formatter instead of function ref #114
Conversation
use a module as formatter instead of function ref
Hello, @andyleclair! This is your first Pull Request that will be reviewed by Ebert, an automatic Code Review service. It will leave comments on this diff with potential issues and style violations found in the code as you push new commits. You can also see all the issues found on this Pull Request on its review page. Please check our documentation for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a wonderful change, thanks @andyleclair. One concern I have is that this breaks compatibility if others have been using the formatter.
Could you also keep the old behaviour by adding definitions with is_function(formatter)
guards? That way users would have a choice to use a module that implements the behaviour, or a function.
@thecodeboss that's a great idea. Give me a few minutes |
@thecodeboss how's that look to you? |
there aren't really any formatting tests, but I guess I could add some if you want! |
lib/formatter.ex
Outdated
@@ -0,0 +1,3 @@ | |||
defmodule Elixometer.Formatter do | |||
@callback format(String.t(), String.t()) :: [String.t()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can give the parameters names in this typespec to make it a bit more readable:
@type metric_type :: :counter | :gauge | :histograms | :spirals | :timer
@callback format(metric_type(), metric_name :: String.t()) :: [String.t()]
Also I think the specis incorrect, the first parameter is an atom instead of a string.
Looks great!
I think that would be helpful, since it's not obvious what a formatter should look like (ie. what is it supposed to return?). Could also help to add a simple example of a formatter in the docs |
I don't really see a great way to test this that wouldn't be just testing that guards and |
README.md
Outdated
|
||
def format(metric_type, name) do | ||
# do your formatting here | ||
# return [String.t()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a more concrete example instead of just a comment. For example
def format(_metric_type, name) do
# appends a constant prefix to metric names, and replaces dashes
# with underscores
["my_prefix", String.replace(name, "-", "_")]
end
Not sure what spec failure you're referring to. Also I think this is okay without tests. Note I'm not one of the maintainers though so I won't be able to merge for you. |
Should Line 292 in a5e6f75
... and if so, then I think we can move the |
@jparise I did consider that, but it's only working on the internal state of the I don't think it's a bad idea though, I did consider it. |
I'm not very familiar with this code, but it looks like Unless I have that wrong, that's an existing bug. |
@jparise updated! |
Hi!
We've found that when attempting to build releases using Distillery, it barfs when trying to use a function ref as a config value.
This PR adds a behaviour so that anyone who wants to add a custom formatter module can do so safely.