-
Notifications
You must be signed in to change notification settings - Fork 172
Add support for gauge metric in static-exporter #1328
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
6b35473
0998771
d823f72
19a272c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ local k = import 'ksonnet-util/kausal.libsonnet'; | |
function(acc, metric) | ||
acc + [ | ||
'# HELP %(name)s %(description)s' % metric, | ||
'# TYPE %(name)s counter' % metric, | ||
'# TYPE %(name)s %(metricType)s' % metric, | ||
] + [ | ||
metric.name + value | ||
for value in metric.values | ||
|
@@ -47,14 +47,17 @@ local k = import 'ksonnet-util/kausal.libsonnet'; | |
}), | ||
|
||
metric:: { | ||
new(name, description):: | ||
new(name, description, metricType='counter'):: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could set this value below and require There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to prefer that over having all the arguments in the constructor? In other words, why have: metric.new('NAME', 'DESCRIPTION') + metric.withMetricType('TYPE') when you can just have: metric.new('NAME', 'DESCRIPTION, 'TYPE') There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, to help me understand our patterns better. Why does the constructor do: self.withName(name)
+ self.withDescription(description)
+ self.withMetricType(metricType) instead of: {
name: name,
description: description,
type: metricType,
} I am thinking it's to use the public API presented by the object so that if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'll answer with a question: At what point do we stop adding things to the constructor? My rule of thumb is to only add arguments to the constructor that are strictly required to create the object. Then create functions for changing the default values of the returned object.
For small objects it doesn't matter that much I guess, for bigger objects these functions may encapsulate larger chunks of code. Opting to ~always use the functions increases consistency. I'm not too nitty-gritty on that, especially for manually written libraries. There is a benefit on composability. Let's say the user wants to prefix the name for all instances from a library. In the object approach, they have to override the constructor: local prefixLib =
lib + {
new(name, description):
lib.new(name, description)
+ { name: 'prefix-' + name },
}; With the function approach: local prefixLib =
lib + {
withName(name):
{ name: 'prefix-' + name },
}; I prefer to do the latter. |
||
self.withName(name) | ||
+ self.withDescription(description), | ||
+ self.withDescription(description) | ||
+ self.withMetricType(metricType), | ||
|
||
withName(name): { name: name }, | ||
|
||
withDescription(description): { description: description }, | ||
|
||
withMetricType(metricType): { type: metricType }, | ||
|
||
local generateValues(labelMap, value=1) = | ||
local labels = [ | ||
key + '="' + labelMap[key] + '"' | ||
|
Uh oh!
There was an error while loading. Please reload this page.