156 Commits

Author SHA1 Message Date
Lucas Thiesen
b89ca19e6a Rename collector to external RPS
Signed-off-by: Lucas Thiesen <lucas.thiesen@zalando.de>
2023-05-23 15:46:38 +02:00
Lucas Thiesen
a276b64576 Fix error string warnings
Signed-off-by: Lucas Thiesen <lucas.thiesen@zalando.de>
2023-05-23 15:46:38 +02:00
Lucas Thiesen
ff6d479f1a Compile regex at plugin level for time optimization
Signed-off-by: Lucas Thiesen <lucas.thiesen@zalando.de>
2023-05-23 15:46:38 +02:00
Lucas Thiesen
cd986058e4 Delete unwanted comments
Signed-off-by: Lucas Thiesen <lucas.thiesen@zalando.de>
2023-05-23 15:46:38 +02:00
Lucas Thiesen
b8532b756b Update HPA to autoscaling/v2 in new collectors
Reference links: https://github.com/zalando-incubator/kube-metrics-adapter/pull/551

Signed-off-by: Lucas Thiesen <lucas.thiesen@zalando.de>
2023-05-23 15:46:37 +02:00
Lucas Thiesen
f28653de74 Use regexp.Compile to avoid performance problems
Signed-off-by: Lucas Thiesen <lucas.thiesen@zalando.de>
2023-05-23 15:46:37 +02:00
Lucas Thiesen
2f5d3f5a42 Change hostname collector type to requests-per-second
Signed-off-by: Lucas Thiesen <lucas.thiesen@zalando.de>
2023-05-23 15:46:37 +02:00
Lucas Thiesen
153d754353 Add support for traffic weight specification
Signed-off-by: Lucas Thiesen <lucas.thiesen@zalando.de>
2023-05-23 15:46:37 +02:00
Lucas Thiesen
02ec2282ab Add multi hostname per metric support
Signed-off-by: Lucas Thiesen <lucas.thiesen@zalando.de>
2023-05-23 15:46:37 +02:00
Lucas Thiesen
aa7b64e637 Add hostname RPS metric collector
Signed-off-by: Lucas Thiesen <lucas.thiesen@zalando.de>
2023-05-23 15:46:36 +02:00
Lucas Thiesen
7633ac551e Extract fake controller to use it in other tests
Signed-off-by: Lucas Thiesen <lucas.thiesen@zalando.de>
2023-05-23 15:46:36 +02:00
Alexander Didenko
c4a1e08fdf Update HPA to autoscaling/v2 apiVersion (#551) 2023-05-03 23:01:19 +02:00
Mikkel Oscar Lyderik Larsen
0794873fcb Add scaling schedule controller to updating status
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2023-04-06 17:53:35 +02:00
Mikkel Oscar Lyderik Larsen
e2a922f110 Move generic functions to controller package
Move defaultTimeZone to a flag.

Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2023-04-06 17:53:17 +02:00
zlawrence
c60253e90c add test for end date in incorrect format
Signed-off-by: zlawrence <zak.lawrence@zalando.de>
2022-12-21 14:08:44 +01:00
zlawrence
680e0feea1 fix nil pointer dereference
Signed-off-by: zlawrence <zak.lawrence@zalando.de>
2022-12-21 14:08:41 +01:00
zlawrence
8ba4d19c35 Add end date support for Repeating schedule. Added tests 2022-12-13 12:53:05 +01:00
zlawrence
37bf73c7fe Add end date support for OneTime schedule 2022-12-12 20:02:15 +01:00
Mikkel Oscar Lyderik Larsen
55ce2d8c3d Update dependencies
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2022-09-13 23:21:39 +02:00
Katyanna Moura
5926f1aea1 Limit ingress support to only networking.k8s.io/v1
Given the deprecation of extensions/v1beta1, remove it from Ingress possibilities.

Signed-off-by: Katyanna Moura <amelie.kn@gmail.com>
2022-06-21 12:46:08 +02:00
Mikkel Oscar Lyderik Larsen
837e7b9c5d Update deps 2022 02 (#391)
* Update example

Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>

* Update dependencies 2022-02

Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2022-02-01 18:13:48 +01:00
Katyanna Moura
71a8e99d1f Fix panic when trying to add key to nil map
Bug was introduced trying to solved the following issue:
> When scenarios where two HPAs reference the same object but have
different metric calculation (e.g. ingresses with different weights),
kube-metrics-adapter calculates the two metrics but always overrides
one of the metrics when saving it to the store.

This commit fixes a issue where without the added `return` the system
was continuing in an invalid states where `labels2metric` wasn't
properly initialized, causing the system to panic.

Signed-off-by: Katyanna Moura <amelie.kn@gmail.com>
2022-01-12 11:29:38 +01:00
Katyanna Moura
4d4c70c553 Fix test filename to match related file
Having the test filename prefix exactly as the tested file name helps systems
to identify the correlation.

Signed-off-by: Katyanna Moura <amelie.kn@gmail.com>
2022-01-12 11:29:38 +01:00
Jonathan Juares Beber
f58db31f98 Define stronger types for metrics store
The metrics store, both the custom and external one, make heavy usage of
maps of strings to strings. This leads to a presumable confusing or at
least hard to read codebase.

This commit tries to increase readability and maintainability of the
metric stores by using custom types. This commit has no effect in
performance or functionality, it's pure aesthetics.

Co-authored-by: Jonathan Juares Beber <jonathanbeber@gmail.com>
Signed-off-by: Katyanna Moura <amelie.kn@gmail.com>
2021-11-24 17:41:03 +01:00
Jonathan Juares Beber
0bf8f5dd0f Use labels hash in the custom metrics store
The current implementation of the metrics store for custom metrics uses
just the object name as key. When scenarios where two HPAs reference the
same object but have different metric calculation (e.g. ingresses with
different weights), kube-metrics-adapter calculates the two metrics but
always overrides one of the metrics when saving it to the store.

This commit implements the use of a labels hash in the custom metrics
store. This way, metrics are identified not just by the referenced
object, but also by its selectors.

Co-authored-by: Katyanna Moura <amelie.kn@gmail.com>
Signed-off-by: Jonathan Juares Beber <jonathanbeber@gmail.com>
2021-11-23 18:11:18 +01:00
Jonathan Juares Beber
0f06db7cdf Upgrade Kubernetes and its friends to 1.21
This commit upgrades all the Kubernetes dependencies to 1.21.5. It
includes regenerated clients and specs.

Signed-off-by: Jonathan Juares Beber <jonathanbeber@gmail.com>
2021-10-27 20:58:18 +02:00
Jonathan Juares Beber
1c9038b2cc Merge pull request #374 from zalando-incubator/configurable-buckets
Make the number of ramp steps configurable
2021-10-25 10:21:32 +02:00
Jonathan Juares Beber
fd4ead837e Make the number of ramp steps configurable
In #371 we introduced steps to make the scaling up possible even when
the HPA forces a 10% change. The problem is that 10% might not be
sufficient for some specific scaling scenarios.

For example, a an application targeting 12 pods and using a
ScalingSchedule with the value of 10000 to achieve that, will require a
target of 833. With 10 ramp steps the 90% bucket will return a metric of
9000 and the HPA calculates (9000/833) 10.8 pods, rounding to 11 pods.
Once the metric reaches the time to return 100% it will won't be
effective, since the change of the current number of pods (11) and the
desired one (12) is less than 10%.

This commit does not try to tackle this problem completely, since the
10% rule is not fixed, might change among different clusters and is also
dependent on the value given to each ScalingSchedule. Therefore, this
commit makes the number of ramp steps configurable via the
`--scaling-schedule-ramp-steps` config flag, defaulting to 10.

Signed-off-by: Jonathan Juares Beber <jonathanbeber@gmail.com>
2021-10-22 15:35:11 +02:00
Mikkel Oscar Lyderik Larsen
4acdf72ef7 Handle more complex array in json path
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-10-14 09:34:15 +02:00
Jonathan Juares Beber
8fe330941a Use 10 buckets on ScalingSchedule ramp-up/down
The HPA has a feature to do not scale up and down when the change in the
metric is less than 10%:

> We'll skip scaling if the ratio is sufficiently close to 1.0 (within a
> globally-configurable tolerance, from the
> `--horizontal-pod-autoscaler-tolerance` flag, which defaults to 0.1.

It could lead to pods scaling up to 10% less than the target for
ScalingSchedules and then not scaling to the actual value if the metric
calculated before was less than 10% of the target.

This commit uses 10 fixed buckets for scaling, this way we know the
metric returned during a scaling event is at least 10% more than a
previous one calculated during the period of ramp up. The same is valid
for the scaling down during a ramp-down

Signed-off-by: Jonathan Juares Beber <jonathanbeber@gmail.com>
2021-09-30 19:01:59 +02:00
Alexey Ermakov
c5411c74b7 Scheduled scaling: add an optional scaling window
Signed-off-by: Alexey Ermakov <alexey.ermakov@zalando.de>
2021-09-24 15:33:49 +02:00
Alexey Ermakov
0dbe769e1b Fix the type for ClusterScalingScheduleList
Signed-off-by: Alexey Ermakov <alexey.ermakov@zalando.de>
2021-09-17 11:29:52 +02:00
Mikkel Oscar Lyderik Larsen
318d47e05e Add deprecation comment
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-08-20 09:33:18 +02:00
Mikkel Oscar Lyderik Larsen
190f0db092 Use labels for specifying Ingress/RouteGroup backend
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-08-20 09:33:17 +02:00
Mikkel Oscar Lyderik Larsen
c618494177 return early if backendName is empty
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-08-20 09:32:48 +02:00
Mikkel Oscar Lyderik Larsen
a08860d06c rename function
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-08-20 09:22:06 +02:00
Mikkel Oscar Lyderik Larsen
6b0afe5180 Add support for scaling based on RouteGroup resource
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-08-19 18:28:58 +02:00
Mikkel Oscar Lyderik Larsen
9722e38f62 Re-generate for go 1.17
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-08-19 18:28:57 +02:00
Jonathan Juares Beber
8415373f3d Update dependencies
this commit updates the k8s dependencies from v0.20.5 to v0.20.9. It
also bundles other dependencies updates.

Signed-off-by: Jonathan Juares Beber <jonathanbeber@gmail.com>
2021-08-11 08:26:00 +02:00
Jonathan Juares Beber
582c94255f Add test for ZMON Key
This commit add tests to the ZMON package when handling the key used on
the metrics query.

Signed-off-by: Jonathan Juares Beber <jonathanbeber@gmail.com>
2021-07-26 15:41:15 +02:00
☃ pitr
1d4beab7a4 fixes for ZMON client
Changes:
- only add group_by "key" if key is provided
- remove deprecated aggregators "dev" and "first"
- add X-Attribution header for query attribution

Signed-off-by: ☃ pitr <peter.vernigorov@zalando.de>
2021-07-24 21:45:02 +02:00
Jonathan Juares Beber
0ad7296d56 Switch Schedule optional fields to pointers
The `Date` and `Period` fields inside the `Schedule` type of the
`[Cluster]ScalingSchedule` CRDs are optional, but in its current
configuration the generated clients can't update or create these
resources since the empty fields do not pass the validation.

This commit updates the `[Cluster]ScalingSchedule.Schedule[*]` `Date`
and `Period` field to pointers, this way a null value is not validated
and the clients are able to update and create resources. It also updates
the collector code and tests to reflect the change.

Signed-off-by: Jonathan Juares Beber <jonathanbeber@gmail.com>
2021-06-30 17:09:48 +02:00
Jonathan Juares Beber
d7f9664d52 Remove HTTP collector check on identifier label
This commit removes the logic that checks for an identifier label in the
http collector config. It also removes the documentation on the README
that mentions that the metric has to be in an old format, removed in
the #219.

Fixes #331

Signed-off-by: Jonathan Juares Beber <jonathanbeber@gmail.com>
2021-06-01 12:33:32 +02:00
Sandor Szücs
64a6b85c73 fix typo Saturday
Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>
2021-05-26 12:03:07 +02:00
Jonathan Juares Beber
a73ef467cd Merge pull request #325 from zalando-incubator/crd-scope-fix
Remove ClusterScalingSchedule clients namespace
2021-05-25 17:30:57 +02:00
Jonathan Juares Beber
e6a04531fb Merge pull request #326 from zalando-incubator/ignore-container-resource-metrics
Ignore ContainerResource metrics
2021-05-25 17:03:27 +02:00
Mikkel Oscar Lyderik Larsen
7289e6f8e2 Ignore ContainerResource metrics
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-05-25 16:45:35 +02:00
Jonathan Juares Beber
60b1dc097a Remove ClusterScalingSchedule clients namespace
During #284 we set the ClusterScalingSchedule scope as `Cluster` but
just for kubebuilder. This flag has no effect in the generated clients.
It means the generated clients expect a namespace argument when handling
ClusterScalingSchedule resources. It works fine to list all of the
resources but makes it impossible to request a specific resource
defining its name.

This commit sets the `+genclient:nonNamespaced` flag for the CRD and
adds the regenerated clients. It does not affect any of the usage of the
clients in this codebase so far.

Signed-off-by: Jonathan Juares Beber <jonathanbeber@gmail.com>
2021-05-21 17:16:57 +02:00
Jonathan Juares Beber
a382dbfe7b Create ScalingSchedule collector
This commit adds two new collectors to the adapter:
- ClusterScalingScheduleCollector; and
- ScalingScheduleCollector

Also, it introduces the required collectors plugins, initialization
logic in the server startup, documentation and deployment example
(including the helm chart). A new config flag is created,
`-scaling-schedule`, and allows to enable and to disable the collection
of such metrics. It's disabled by default.

This collectors are the required logic to utilise the CRDs introduced in
the #284 pull request. It makes use of the kubernetes go-client
implementations of a [Store][0] and [Reflector][1].

[0]: https://pkg.go.dev/k8s.io/client-go/tools/cache#Store
[1]: https://pkg.go.dev/k8s.io/client-go/tools/cache#Reflector

Signed-off-by: Jonathan Juares Beber <jonathanbeber@gmail.com>
2021-05-21 14:29:11 +02:00
Anatolii Dutchak
e16bacb24e Changed message text and level
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-05-05 11:22:51 +03:00