NewSession is being deprecated, NewSessionWithConfig handles things
such as role arns. This fixes permissions issues for users using
role arns for service accounts.
Signed-off-by: Ewan Valentine <ewan.valentine89@gmail.com>
* Use labels for mapping metric types to metrics
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
* Log warning when old format is used
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
* Test NewCollector logic for external metrics
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
Allow configuration per metric for connect and request timeouts
when querying pods for JSON metrics.
Signed-off-by: Abe Friesen <2319792+doyshinda@users.noreply.github.com>
Fetching metrics from pods sequentially, with a large number of
pods, can result in poor performance when some of those pods have
been terminated by the HPA in a normal scale down event.
Signed-off-by: Abe Friesen <2319792+doyshinda@users.noreply.github.com>
Adds a new metric-config option named `rawQuery`. The value of
this option will be appended to the metric `path` as URL query
parameters to be used by the pod's application. E.g.,:
```
metric-config.pods.requests-per-second.json-path/rawQuery: "foo=bar&baz=bop"
```
will apppend `?foo=bar&baz=bop` to the URL.
Signed-off-by: Abe Friesen <2319792+doyshinda@users.noreply.github.com>
* This commit adds a --disregard-incompatible-hpas that makes the HPA
provider stop erroring out when a collector cannot be created for a
metric in a HPA. Useful when kube-metrics-adapter runs alongside another
metrics provider. Fixes issue #94.
Signed-off-by: Tomás Pinho <me@tomaspinho.com>
* Make tests pass
Signed-off-by: Tomás Pinho <me@tomaspinho.com>
* Wraps the Plugin Not Found error in a new type that can be checked by the caller of a function to determine if its contents should be logged or added as an event to the HPA, when this HPA is incompatible.
The disregardIncompatibleHPAs is now targetting only the log or addition of the same event.
Signed-off-by: Tomás Pinho <me@tomaspinho.com>
* Invert if expression to select when we should log
CreateNewMetricsCollector errors: don't log when both conditions are true - it's not a PluginNotFoundError
and disregardIncompatibleHPAs flag is set to true. This way, if an error
is NOT PluginNotFoundError it will always be logged, and when it IS
PluginNotFoundError it will only be logged when
disregardIncompatibleHPAs is false.
Signed-off-by: Tomás Pinho <me@tomaspinho.com>
* Remove redundant "whether to"
Signed-off-by: Tomás Pinho <me@tomaspinho.com>
* Add test case for updating HPAs via HPA Provider while disregarding
incompatible HPAs.
Signed-off-by: Tomás Pinho <me@tomaspinho.com>
into cases of []<number>, being <number> a number type such as int,
float32, float64. This is because Go can't type cast slices of
interface{} out right because it's impossible to know the true types of
the slice members beforehand.
Signed-off-by: Tomás Pinho <me@tomaspinho.com>
* This is the initial implementation of support for JSONPath expressions
that return arrays of values instead of a single value.
This extends the
collector to define a few handy reducer functions that take in the slice
of float64 and return a single value. It also allows the user to define
which reducer function to use via the
"metric-config.<metricType>.<metricName>.json-path/reducer-func"
annotation, which
can have the values of 'avg', 'min', 'max' and 'sum'.
For instance, the Ruby puma webserver exposes metrics of the form of $.worker_status[*].last_status.pool_capacity that have to be consumed as an array of values to be properly targetted.
Signed-off-by: Tomás Pinho <me@tomaspinho.com>
* Renames "reducerFunc" to "aggregator" for consistency with other
collectors. Renames the annotation from
"metric-config.<metricType>.<metricName>.json-path/reducer-func" to "metric-config.<metricType>.<metricName>.json-path/aggregator".
Signed-off-by: Tomás Pinho <me@tomaspinho.com>
* Return error instead of defaulting to the avg aggregator, when no valid
aggregator name was specified and the JSONPath value is a slice of
numbers.
Signed-off-by: Tomás Pinho <me@tomaspinho.com>
* Fix index out of range on initialized output slice that was found while
writing tests.
Signed-off-by: Tomás Pinho <me@tomaspinho.com>
* Add tests for all added functions + NewJSONPathMetricsGetter
Signed-off-by: Tomás Pinho <me@tomaspinho.com>
* Add documentation on the `aggregator` option.
Signed-off-by: Tomás Pinho <me@tomaspinho.com>
* reducer function -> aggregator function
Signed-off-by: Tomás Pinho <me@tomaspinho.com>
* Fix comment to account for returned error.
Signed-off-by: Tomás Pinho <me@tomaspinho.com>
* Drop MaxWeightedCollector (we don't want max anyway, we want sum)
* Use Prometheus to add up all matching metrics and scale them; this
has a nice side effect of ensuring that unused hostnames don't cause
an error when collecting the metrics
* Update the tests a bit
Signed-off-by: Alexey Ermakov <alexey.ermakov@zalando.de>
This adds support for `averageValue` for the `request-per-second` metric
based on Ingress Objects. This is only supported from Kubernetes
`>=v1.14` (https://github.com/kubernetes/kubernetes/pull/72872).
When defining the HPA with `autoscaling/v2beta1` you still need to
define `targetValue` even though it won't be used when `averageValue` is
set. Once we default to `autoscaling/v2beta2` this akward API will be
gone.
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
This is a slight refactoring/unification of how metric
labels/annotations are parsed and handled accross collectors. This is
done to prevent crashes when labels are not defined on external metrics.
Fix#69
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
Fixes the response from `GetMetricsBySelector` in case no metrics are
found. This issue caused a panic in kube-controller-manager:
https://github.com/kubernetes/kubernetes/pull/80392Fix#40
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
* Prevent leaking collectors when HPA gets updated
This fixes an issue where collectors would be leaking when HPAs are
getting updated.
Fix this by stopping the collector started for the previous version of
the HPA.
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
* Add tests to verify old collector is removed
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
* Return a value when atleast one of the metrics returns a value
Signed-off-by: Arjun Naik <arjun.rn@gmail.com>
* Added test for max weighted collector
Signed-off-by: Arjun Naik <arjun.rn@gmail.com>
This fixes an issue of setting up a ZMON collector where the incorrect
key `Configuration` was used, which was not initialized in the metrics
config parser. The `Config` key is the right one to use.
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>