* 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>
* Added weighting of rps metrics based on backend weights
Signed-off-by: Arjun Naik <arjun.rn@gmail.com>
* Updated documented with instructions on how to use the backend weighting
Signed-off-by: Arjun Naik <arjun.rn@gmail.com>
* Changed separator for RPS metric and added flag to specify backend weights annotation.
Signed-off-by: Arjun Naik <arjun.rn@gmail.com>
* Allow for multiple backends with for weighting.
Signed-off-by: Arjun Naik <arjun.rn@gmail.com>
* Look at total replicas instead of readyReplicas
In cases where replicas take a bit of time to get ready, the Stackset Controller just keeps on scaling. To avoid this issue,
using the total replicas instead of replicas that are ready.
Signed-off-by: Muhammad Muaaz Saleem <muhammad.muaaz.saleem@zalando.de>
* Fix bitbucket clones
Signed-off-by: Alexey Ermakov <alexey.ermakov@zalando.de>
* Updating .gitignore
Signed-off-by: Muhammad Muaaz Saleem <muhammad.muaaz.saleem@zalando.de>
* Fixing Typo
Signed-off-by: Muhammad Muaaz Saleem <muhammad.muaaz.saleem@zalando.de>
* Adding tests to avoid regression
Testing that collectors depend on Resource.Status.Replicas and not
Resource.Status.ReadyReplicas
Signed-off-by: Muhammad Muaaz Saleem <muhammad.muaaz.saleem@zalando.de>
Adding tests for error cases in metric_store.go. This will primarily
protect against regression.
Signed-off-by: Muhammad Muaaz Saleem <muhammad.muaaz.saleem@zalando.de>
Making metrics expiration TTL configurable globally configurable.
This is so RemoveExpired can be tested. Not making the TTL configurable
per metric yet because it could change behaviour in production.
Signed-off-by: Muhammad Muaaz Saleem <muhammad.muaaz.saleem@zalando.de>
Testing that metrics get removed once expired. Tests are failing
because metric.TTL isn't configurable at the moment
Signed-off-by: Muhammad Muaaz Saleem <muhammad.muaaz.saleem@zalando.de>