Compare commits

...

84 Commits

Author SHA1 Message Date
Jonathan Juares Beber
d1969a3020 Merge pull request #348 from zalando-incubator/pitr-zmon
fixes for ZMON client
2021-07-26 15:57:11 +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
c626f414db remove deprecated zmon aggregators in README
Signed-off-by: ☃ pitr <peter.vernigorov@zalando.de>
2021-07-26 11:14:27 +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
eefd5ef512 Merge pull request #346 from zalando-incubator/dependabot/go_modules/github.com/aws/aws-sdk-go-1.39.2
Bump github.com/aws/aws-sdk-go from 1.38.70 to 1.39.2
2021-07-08 16:20:03 +02:00
dependabot[bot]
599b3bf805 Bump github.com/aws/aws-sdk-go from 1.38.70 to 1.39.2
Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.38.70 to 1.39.2.
- [Release notes](https://github.com/aws/aws-sdk-go/releases)
- [Changelog](https://github.com/aws/aws-sdk-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-go/compare/v1.38.70...v1.39.2)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-08 13:00:42 +00:00
Mikkel Oscar Lyderik Larsen
ecf21df9c0 Merge pull request #338 from zalando-incubator/dependabot/go_modules/github.com/aws/aws-sdk-go-1.38.70
Bump github.com/aws/aws-sdk-go from 1.38.47 to 1.38.70
2021-07-08 14:52:50 +02:00
dependabot[bot]
ecd296e644 Bump github.com/aws/aws-sdk-go from 1.38.47 to 1.38.70
Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.38.47 to 1.38.70.
- [Release notes](https://github.com/aws/aws-sdk-go/releases)
- [Changelog](https://github.com/aws/aws-sdk-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-go/compare/v1.38.47...v1.38.70)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-01 07:19:53 +00:00
Jonathan Juares Beber
446b7f01ea Merge pull request #334 from zalando-incubator/nil-fields
Switch Schedule optional fields to pointers
2021-06-30 17:17:15 +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
9da155554b Merge pull request #332 from zalando-incubator/drop-identifier
Remove HTTP collector check on identifier label
2021-06-01 13:53:21 +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
Jonathan Juares Beber
85f6dda229 Merge pull request #328 from zalando-incubator/fix/typo
fix typo Saturday
2021-05-26 17:02:01 +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
f41af0d82b Merge pull request #329 from zalando-incubator/dependabot/go_modules/github.com/aws/aws-sdk-go-1.38.47
Bump github.com/aws/aws-sdk-go from 1.38.46 to 1.38.47
2021-05-26 11:52:08 +02:00
dependabot[bot]
194bede7a3 Bump github.com/aws/aws-sdk-go from 1.38.46 to 1.38.47
Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.38.46 to 1.38.47.
- [Release notes](https://github.com/aws/aws-sdk-go/releases)
- [Changelog](https://github.com/aws/aws-sdk-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-go/compare/v1.38.46...v1.38.47)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-26 08:51:08 +00:00
dependabot[bot]
c4f5efb6a7 Bump github.com/prometheus/common from 0.23.0 to 0.25.0 (#323)
Bumps [github.com/prometheus/common](https://github.com/prometheus/common) from 0.23.0 to 0.25.0.
- [Release notes](https://github.com/prometheus/common/releases)
- [Commits](https://github.com/prometheus/common/compare/v0.23.0...v0.25.0)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-26 10:44:06 +02:00
dependabot[bot]
51e9378ee6 Bump github.com/aws/aws-sdk-go from 1.38.44 to 1.38.46 (#327)
Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.38.44 to 1.38.46.
- [Release notes](https://github.com/aws/aws-sdk-go/releases)
- [Changelog](https://github.com/aws/aws-sdk-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-go/compare/v1.38.44...v1.38.46)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-26 10:43:43 +02:00
Jonathan Juares Beber
ce27ef1798 Merge pull request #324 from zalando-incubator/dependabot/go_modules/github.com/aws/aws-sdk-go-1.38.44
Bump github.com/aws/aws-sdk-go from 1.38.30 to 1.38.44
2021-05-25 19:18:14 +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
dependabot[bot]
6b46cc2599 Bump github.com/aws/aws-sdk-go from 1.38.30 to 1.38.44
Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.38.30 to 1.38.44.
- [Release notes](https://github.com/aws/aws-sdk-go/releases)
- [Changelog](https://github.com/aws/aws-sdk-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-go/compare/v1.38.30...v1.38.44)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-21 14:55:46 +00:00
Jonathan Juares Beber
6f9aba8db8 Merge pull request #315 from zalando-incubator/time-based-scaling
Create ScalingSchedule collector
2021-05-21 16:46:10 +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
Jonathan Juares Beber
7a68304389 Merge pull request #311 from Miniland1333/patch-2
Bump to v0.1.10 for helm
2021-05-12 18:36:34 +02:00
Jonathan Juares Beber
7044e79b08 Merge pull request #312 from adutchak-x/feature/stop-processing-non-runing-pods
Feature/stop processing non runing pods
2021-05-06 10:35:17 +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
Jonathan Juares Beber
726c1e691d Merge pull request #313 from zalando-incubator/dependabot/go_modules/github.com/prometheus/common-0.23.0
Bump github.com/prometheus/common from 0.20.0 to 0.23.0
2021-05-03 11:49:11 +02:00
Jonathan Juares Beber
debc90ca72 Merge pull request #314 from zalando-incubator/dependabot/go_modules/github.com/aws/aws-sdk-go-1.38.30
Bump github.com/aws/aws-sdk-go from 1.38.18 to 1.38.30
2021-05-03 11:48:57 +02:00
dependabot[bot]
6343c8ea15 Bump github.com/aws/aws-sdk-go from 1.38.18 to 1.38.30
Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.38.18 to 1.38.30.
- [Release notes](https://github.com/aws/aws-sdk-go/releases)
- [Changelog](https://github.com/aws/aws-sdk-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-go/compare/v1.38.18...v1.38.30)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-01 07:05:41 +00:00
dependabot[bot]
eb0575f11e Bump github.com/prometheus/common from 0.20.0 to 0.23.0
Bumps [github.com/prometheus/common](https://github.com/prometheus/common) from 0.20.0 to 0.23.0.
- [Release notes](https://github.com/prometheus/common/releases)
- [Commits](https://github.com/prometheus/common/compare/v0.20.0...v0.23.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-01 07:05:08 +00:00
Anatolii Dutchak
52bfbbb1b0 Goimported pod_collector_test.go
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-30 18:08:30 +03:00
Anatolii Dutchak
cf5872ef08 Fixed formatting
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-30 18:00:23 +03:00
Anatolii Dutchak
b5432fb1f3 Fixed formatting
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-30 17:58:44 +03:00
Anatolii Dutchak
5466badd90 Added pod.DeletionTimestamp condition check
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-30 16:04:32 +03:00
Jonathan Juares Beber
aef1837e47 Merge pull request #310 from Miniland1333/patch-1
Updated apiservice to v1
2021-04-28 16:16:00 +02:00
Henry Agnew
4e86d6ae34 Reverted changes to metrics API. Retain API registration changes
Testing indicates that metrics API v1beta2 is not a suitable drop-in replacement for v1beta1, and v1 does not exist at this time.
Signed-off-by: Henry Agnew <henryd.agnew@gmail.com>
2021-04-27 10:31:48 -07:00
Miniland1333
2874c1a6a7 Update Chart.yaml
Signed-off-by: Henry Agnew <henryd.agnew@gmail.com>
2021-04-26 22:19:37 -07:00
Miniland1333
b5006746f0 Bump to v0.1.10
Signed-off-by: Henry Agnew <henryd.agnew@gmail.com>
2021-04-26 22:19:37 -07:00
Miniland1333
9496ab7fd3 Update external-metrics-apiservice.yaml
Signed-off-by: Henry Agnew <henryd.agnew@gmail.com>
2021-04-26 11:26:34 -07:00
Miniland1333
aa7f86291e Update custom-metrics-apiservice.yaml
Signed-off-by: Henry Agnew <henryd.agnew@gmail.com>
2021-04-26 11:26:34 -07:00
Miniland1333
486a6c4262 Update external-metrics-apiservice.yaml
Signed-off-by: Henry Agnew <henryd.agnew@gmail.com>
2021-04-26 11:26:34 -07:00
Miniland1333
aaf66f31a0 Update custom-metrics-apiservice.yaml
Signed-off-by: Henry Agnew <henryd.agnew@gmail.com>
2021-04-26 11:26:34 -07:00
Jonathan Juares Beber
e5bee93bf6 Merge pull request #309 from iamgrewal7/master
add commandline flags to set GC interval and metrics TTL
2021-04-26 14:28:02 +02:00
Harman Singh
aae3772472 add commandline flags to set GC interval and metrics TTL
Signed-off-by: Harman Singh <iamgrewal7@gmail.com>
2021-04-26 00:01:04 -07:00
Jonathan Juares Beber
76d3726e5b Merge pull request #308 from adutchak-x/feature/improve-pod-collector
Feature/improve pod collector
2021-04-21 19:39:49 +02:00
Anatolii Dutchak
ea4a651afe Fixed tests
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-21 18:37:16 +03:00
Anatolii Dutchak
721c6553d8 Added conditions[i].Status == corev1.ConditionTrue check
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-21 18:25:49 +03:00
Anatolii Dutchak
5aa2272e37 Removed debug message, changed podReadyAge >= c.minPodReadyAge
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-20 12:33:47 +03:00
Anatolii Dutchak
b9300d1e46 Added namespace to logs, simplified GetPodReadyAge method
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-20 11:21:24 +03:00
Anatolii Dutchak
5747b6c9de Renamed min-pod-age to min-pod-ready-age. Considering LastTransitionTime for pod ready age.
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-19 18:51:39 +03:00
Anatolii Dutchak
6d15a1635a goimported pkg/collector/pod_collector_test.go
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-17 08:17:59 +03:00
Anatolii Dutchak
4090ab8b32 goimported pkg/annotations/parser_test.go
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-17 01:08:42 +03:00
Anatolii Dutchak
1f56abf931 Corrected formatting
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-17 00:52:00 +03:00
Anatolii Dutchak
f216070630 Introduced min-pod-age configuration key. Added Pod condition handling
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-17 00:52:00 +03:00
Jonathan Juares Beber
8725f02db7 Merge pull request #295 from adutchak-x/bugfix/fix-disregard-incompatible-hpas-error-handling
Bugfix/fix disregard incompatible hpas error handling
2021-04-16 12:10:17 +02:00
Anatolii Dutchak
240452ca27 Merge pull request #1 from zalando-incubator/bugfix/fix-disregard-incompatible-hpas-error-handling-check-events
Check for events to ensure invalid HPAs are ignored
2021-04-16 12:35:16 +03:00
Mikkel Oscar Lyderik Larsen
45d7863e73 Check for events to ensure invalid HPAs are ignored
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-04-16 10:05:27 +02:00
Anatolii Dutchak
87f249d36b goimported hpa.go
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-14 22:25:23 +03:00
Anatolii Dutchak
9967a55df8 Updated errors handling for updateHPAs method
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-14 22:25:23 +03:00
adutchak-x
adf0792079 Update pkg/collector/collector.go
Co-authored-by: Jonathan Juares Beber <jonathanbeber@gmail.com>
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-14 22:25:23 +03:00
Anatolii Dutchak
99fa5c42ed Replaced spaces with tabs
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-14 22:25:23 +03:00
Anatolii Dutchak
188cc91574 Reverted error check to errors.Is(), implemented Is() method for PluginNotFoundError
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-14 22:25:23 +03:00
Anatolii Dutchak
a8ff0ed6f0 Corrected comment formatting
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-14 22:25:23 +03:00
Anatolii Dutchak
cc9279b283 Chnaged error type check from errors.Is() to errors.As() because errors.Is() always returns False
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
2021-04-14 22:25:23 +03:00
Jonathan Juares Beber
9bb7d976a0 Merge pull request #307 from zalando-incubator/update-deps-2021-04-13-2
Update dependencies
2021-04-13 16:08:57 +02:00
Mikkel Oscar Lyderik Larsen
816661f7fd Don't deepcopy-gen on string types
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-04-13 13:11:40 +02:00
Mikkel Oscar Lyderik Larsen
7ae70d798d Update dependencies
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-04-13 11:52:50 +02:00
Mikkel Oscar Lyderik Larsen
0ef5ad1cfe Merge pull request #298 from zalando-incubator/document-interval-settings
Clearly document interval config
2021-04-13 11:35:57 +02:00
Jonathan Juares Beber
c86235636b Merge pull request #297 from zalando-incubator/update-deps-2021-04-13
Update dependencies
2021-04-13 11:34:16 +02:00
Mikkel Oscar Lyderik Larsen
2d119e68e4 Clearly document interval config
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-04-13 11:28:50 +02:00
Mikkel Oscar Lyderik Larsen
df3efe0e39 Update makefile dependencies
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-04-13 11:17:46 +02:00
Mikkel Oscar Lyderik Larsen
a5b5cb91c3 Update dependencies
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-04-13 10:48:44 +02:00
Jonathan Juares Beber
ebcf99ad27 Merge pull request #284 from zalando-incubator/time-based-scaling
Create first version of ScalingSchedule CRD
2021-03-23 15:07:09 +01:00
Jonathan Juares Beber
3d450ad2c2 Create first version of ScalingSchedule CRDs
Some cases and users actually know when their applications will have a
high workload and, therefore, autoscaling support for time based scaling
is a desired feature.

This commit creates the first version of two CRDs called
`ScalingSchedule` and `ClusterScalingSchedule`.
The CRDs describe one or multiples schedules inside them. The schedules
contains the information of when the time based scaling starts, if it
happens once or multiple times, its duration and, a configurable value
that later can be used by HPAs to scale applications.

The only difference between the two CRDs is their scope.
`ClusterScalingSchedule` aims to attend cluster wide schedules, to
multiple applications, while `ScalingSchedule` has to be deployed with
each application into the same namespace.

This commit does not creates any metric, it's a noop change that creates
just the CRD and import tools required to generate the CRD and others
required code, as `deepCopy` functions and clients.

Signed-off-by: Jonathan Juares Beber <jonathanbeber@gmail.com>
2021-03-23 11:07:56 +01:00
Mikkel Oscar Lyderik Larsen
78a9b5c253 Merge pull request #283 from zalando-incubator/update-deps-2021-03-01
Update dependencies
2021-03-01 12:45:36 +01:00
Mikkel Oscar Lyderik Larsen
4e2b9d9788 Update dependencies
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-03-01 11:50:33 +01:00
Mikkel Oscar Lyderik Larsen
38aeb4deed Stable comparison in test
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-03-01 11:50:32 +01:00
Mikkel Oscar Lyderik Larsen
b7aa886546 Namespace external metrics (#259)
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-02-19 11:11:29 +01:00
Mikkel Oscar Lyderik Larsen
942e753f87 Use Github actions instead of travis (#270)
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-02-19 10:31:20 +01:00
Jonathan Juares Beber
86ed6ec102 Merge pull request #269 from zalando-incubator/update-dependencies-2021-02-01
Update dependencies
2021-02-01 18:49:22 +01:00
Mikkel Oscar Lyderik Larsen
b313c963b6 Update dependencies
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2021-02-01 10:26:01 +01:00
78 changed files with 6513 additions and 777 deletions

25
.github/workflows/ci.yaml vendored Normal file
View File

@ -0,0 +1,25 @@
name: ci
on: [push, pull_request]
env:
GO111MODULE: on
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.16'
- run: go version
- run: go get github.com/mattn/goveralls
env:
GO111MODULE: off
- run: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_RELEASE}
env:
GOLANGCI_RELEASE: v1.37.0
- run: make build.docker
- run: make test
- run: make check
- run: goveralls -coverprofile=profile.cov -service=github
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
build/
apiserver.local.config/
.idea/
profile.cov
vendor/

View File

@ -1,20 +0,0 @@
language: go
dist: xenial
go:
- "1.14.x"
env:
- GO111MODULE=on GOLANGCI_RELEASE="v1.21.0"
before_install:
- GO111MODULE=off go get github.com/mattn/goveralls
- GO111MODULE=off go get github.com/lawrencewoodman/roveralls
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_RELEASE}
script:
- make test
- make build.docker
- make check
- roveralls
- goveralls -v -coverprofile=roveralls.coverprofile -service=travis-ci

View File

@ -1,6 +1,8 @@
FROM registry.opensource.zalan.do/library/alpine-3.12:latest
LABEL maintainer="Team Teapot @ Zalando SE <team-teapot@zalando.de>"
RUN apk add --no-cache tzdata
# add binary
ADD build/linux/kube-metrics-adapter /

View File

@ -10,6 +10,10 @@ GOPKGS = $(shell go list ./...)
BUILD_FLAGS ?= -v
OPENAPI ?= pkg/api/generated/openapi/zz_generated.openapi.go
LDFLAGS ?= -X main.version=$(VERSION) -w -s
CRD_SOURCES = $(shell find pkg/apis/zalando.org -name '*.go')
CRD_TYPE_SOURCE = pkg/apis/zalando.org/v1/types.go
GENERATED_CRDS = docs/scaling_schedules_crd.yaml
GENERATED = pkg/apis/zalando.org/v1/zz_generated.deepcopy.go
default: build.local
@ -18,14 +22,22 @@ clean:
rm -rf build
rm -rf $(OPENAPI)
test:
go test -v $(GOPKGS)
test: $(GENERATED)
go test -v -coverprofile=profile.cov $(GOPKGS)
check:
check: $(GENERATED)
go mod download
golangci-lint run --timeout=2m ./...
$(GENERATED): go.mod $(CRD_TYPE_SOURCE) $(OPENAPI)
./hack/update-codegen.sh
$(GENERATED_CRDS): $(GENERATED) $(CRD_SOURCES)
go run sigs.k8s.io/controller-tools/cmd/controller-gen crd:crdVersions=v1 paths=./pkg/apis/... output:crd:dir=docs || /bin/true || true
mv docs/zalando.org_clusterscalingschedules.yaml docs/cluster_scaling_schedules_crd.yaml
mv docs/zalando.org_scalingschedules.yaml docs/scaling_schedules_crd.yaml
$(OPENAPI): go.mod
go run k8s.io/kube-openapi/cmd/openapi-gen \
--go-header-file hack/boilerplate.go.txt \
@ -36,17 +48,17 @@ $(OPENAPI): go.mod
-O zz_generated.openapi \
-r /dev/null
build.local: build/$(BINARY)
build.local: build/$(BINARY) $(GENERATED_CRDS)
build.linux: build/linux/$(BINARY)
build.osx: build/osx/$(BINARY)
build/$(BINARY): go.mod $(SOURCES) $(OPENAPI)
build/$(BINARY): go.mod $(SOURCES) $(GENERATED)
CGO_ENABLED=0 go build -o build/$(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" .
build/linux/$(BINARY): go.mod $(SOURCES) $(OPENAPI)
build/linux/$(BINARY): go.mod $(SOURCES) $(GENERATED)
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/linux/$(BINARY) -ldflags "$(LDFLAGS)" .
build/osx/$(BINARY): go.mod $(SOURCES) $(OPENAPI)
build/osx/$(BINARY): go.mod $(SOURCES) $(GENERATED)
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/osx/$(BINARY) -ldflags "$(LDFLAGS)" .
build.docker: build.linux

162
README.md
View File

@ -10,7 +10,7 @@ It supports scaling based on [Prometheus metrics](https://prometheus.io/), [SQS
It discovers Horizontal Pod Autoscaling resources and starts to collect the
requested metrics and stores them in memory. It's implemented using the
[custom-metrics-apiserver](https://github.com/kubernetes-incubator/custom-metrics-apiserver)
[custom-metrics-apiserver](https://github.com/kubernetes-sigs/custom-metrics-apiserver)
library.
Here's an example of a `HorizontalPodAutoscaler` resource configured to get
@ -110,6 +110,8 @@ metadata:
metric-config.pods.requests-per-second.json-path/port: "9090"
metric-config.pods.requests-per-second.json-path/scheme: "https"
metric-config.pods.requests-per-second.json-path/aggregator: "max"
metric-config.pods.requests-per-second.json-path/interval: "60s" # optional
metric-config.pods.requests-per-second.json-path/min-pod-ready-age: "30s" # optional
spec:
scaleTargetRef:
apiVersion: apps/v1
@ -174,6 +176,11 @@ metric-config.pods.requests-per-second.json-path/connect-timeout: 500ms
The default for both of the above values is 15 seconds.
The `min-pod-ready-age` configuration option instructs the service to start collecting metrics from the pods only if they are "older" (time elapsed after pod reached "Ready" state) than the specified amount of time.
This is handy when pods need to warm up before HPAs will start tracking their metrics.
The default value is 0 seconds.
## Prometheus collector
The Prometheus collector is a generic collector which can map Prometheus
@ -202,16 +209,6 @@ the trade-offs between the two approaches.
| `prometheus-query` | Generic metric which requires a user defined query. | External | | `>=1.12` |
| *custom* | No predefined metrics. Metrics are generated from user defined queries. | Object | *any* | `>=1.12` |
### Configure Scrape Interval
There is a way to set the interval via an annotation like:
```yaml
metric-config.external.prometheus-query.prometheus/interval: 30s
```
Default is 1 minute.
### Example: External Metric
This is an example of an HPA configured to get metrics based on a Prometheus
@ -234,6 +231,7 @@ metadata:
# metric-config.<metricType>.<metricName>.<collectorType>/<configKey>
metric-config.external.processed-events-per-second.prometheus/query: |
scalar(sum(rate(event-service_events_count{application="event-service",processed="true"}[1m])))
metric-config.external.processed-events-per-second.prometheus/interval: "60s" # optional
spec:
scaleTargetRef:
apiVersion: apps/v1
@ -411,6 +409,7 @@ metadata:
// Rename "_value" to "metricvalue" for letting the metrics server properly unmarshal the result.
|> rename(columns: {_value: "metricvalue"})
|> keep(columns: ["metricvalue"])
metric-config.external.queue-depth.influxdb/interval: "60s" # optional
spec:
scaleTargetRef:
apiVersion: apps/v1
@ -532,6 +531,7 @@ metadata:
# metric-config.<metricType>.<metricName>.<collectorType>/<configKey>
metric-config.external.my-zmon-check.zmon/key: "custom.*"
metric-config.external.my-zmon-check.zmon/tag-application: "my-custom-app-*"
metric-config.external.my-zmon-check.zmon/interval: "60s" # optional
spec:
scaleTargetRef:
apiVersion: apps/v1
@ -587,8 +587,8 @@ For instance if you define the entity filter
then you might want to get an average over the metrics for those three
entities. This would be possible by using the `avg` aggregator. The default
aggregator is `last` which returns only the latest metric point from the
query. The supported aggregation functions are `avg`, `dev`, `count`,
`first`, `last`, `max`, `min`, `sum`, `diff`. See the [KariosDB docs](https://kairosdb.github.io/docs/build/html/restapi/Aggregators.html) for
query. The supported aggregation functions are `avg`, `count`,
`last`, `max`, `min`, `sum`, `diff`. See the [KariosDB docs](https://kairosdb.github.io/docs/build/html/restapi/Aggregators.html) for
details.
The `duration` defines the duration used for the timeseries query. E.g. if you
@ -629,6 +629,7 @@ metadata:
metric-config.external.unique-metric-name.json-path/json-key: "$.some-metric.value"
metric-config.external.unique-metric-name.json-path/endpoint: "http://metric-source.app-namespace:8080/metrics"
metric-config.external.unique-metric-name.json-path/aggregator: "max"
metric-config.external.unique-metric-name.json-path/interval: "60s" # optional
spec:
scaleTargetRef:
apiVersion: apps/v1
@ -649,12 +650,141 @@ spec:
type: AverageValue
```
The HTTP collector similar to the Pod Metrics collector. The metric name should always be `http`.
This value is also used in the annotations to configure the metrics adapter to query the required
target. The following configuration values are supported:
The HTTP collector similar to the Pod Metrics collector. The following
configuration values are supported:
- `json-key` to specify the JSON path of the metric to be queried
- `endpoint` the fully formed path to query for the metric. In the above example a Kubernetes _Service_
in the namespace `app-namespace` is called.
- `aggregator` is only required if the metric is an array of values and specifies how the values
are aggregated. Currently this option can support the values: `sum`, `max`, `min`, `avg`.
### Scrape Interval
It's possible to configure the scrape interval for each of the metric types via
an annotation:
```yaml
metric-config.<metricType>.<metricName>.<collectorType>/interval: "30s"
```
The default is `60s` but can be reduced to let the adapter collect metrics more
often.
## ScalingSchedule Collectors
The `ScalingSchedule` and `ClusterScalingSchedule` collectors allow
collecting time-based metrics from the respective CRD objects specified
in the HPA.
### Supported metrics
| Metric | Description | Type | K8s Versions |
| ---------- | -------------- | ------- | -- |
| ObjectName | The metric is calculated and stored for each `ScalingSchedule` and `ClusterScalingSchedule` referenced in the HPAs | `ScalingSchedule` and `ClusterScalingSchedule` | `>=1.16` |
### Example
This is an example of using the ScalingSchedule collectors to collect
metrics from a deployed kind of the CRD. First, the schedule object:
```yaml
apiVersion: zalando.org/v1
kind: ClusterScalingSchedule
metadata:
name: "scheduling-event"
spec:
schedules:
- type: OneTime
date: "2021-10-02T08:08:08+02:00"
durationMinutes: 30
value: 100
- type: Repeating
durationMinutes: 10
value: 120
period:
startTime: "15:45"
timezone: "Europe/Berlin"
days:
- Mon
- Wed
- Fri
```
This resource defines a scheduling event named `scheduling-event` with
two schedules of the kind `ClusterScalingSchedule`.
`ClusterScalingSchedule` objects aren't namespaced, what means it can be
referenced by any HPA in any namespace in the cluster. `ScalingSchedule`
have the exact same fields and behavior, but can be referenced just by
HPAs in the same namespace. The schedules can have the type `Repeating`
or `OneTime`.
This example configuration will generate the following result: at
`2021-10-02T08:08:08+02:00` for 30 minutes a metric with the value of
100 will be returned. Every Monday, Wednesday and Friday, starting at 15
hours and 45 minutes (Berlin time), a metric with the value of 120 will
be returned for 10 minutes. It's not the case of this example, but if multiple
schedules collide in time, the biggest value is returned.
Check the CRDs definitions
([ScalingSchedule](./docs/scaling_schedules_crd.yaml),
[ClusterScalingSchedule](./docs/cluster_scaling_schedules_crd.yaml)) for
a better understanding of the possible fields and their behavior.
An HPA can reference the deployed `ClusterScalingSchedule` object as
this example:
```yaml
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: "myapp-hpa"
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp
minReplicas: 1
maxReplicas: 15
metrics:
- type: Object
object:
describedObject:
apiVersion: zalando.org/v1
kind: ClusterScalingSchedule
name: "scheduling-event"
metric:
name: "scheduling-event"
target:
type: AverageValue
averageValue: "10"
```
The name of the metric is equal to the name of the referenced object.
The `target.averageValue` in this example is set to 10. This value will
be used by the HPA controller to define the desired number of pods,
based on the metric obtained (check the [HPA algorithm
details](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#algorithm-details)
for more context). This HPA configuration explicitly says that each pod
of this application supports 10 units of the `ClusterScalingSchedule`
metric. Multiple applications can share the same
`ClusterScalingSchedule` or `ScalingSchedule` event and have a different
number of pods based on its `target.averageValue` configuration.
In our specific example at `2021-10-02T08:08:08+02:00` as the metric has
the value 100, this application will scale to 10 pods (100/10). Every
Monday, Wednesday and Friday, starting at 15 hours and 45 minutes
(Berlin time) the application will scale to 12 pods (120/10). Both
scaling up will last at least the configured duration times of the
schedules. After that, regular HPA scale down behavior applies.
Note that these number of pods are just considering these custom
metrics, the normal HPA behavior still applies, such as: in case of
multiple metrics the biggest number of pods is the utilized one, HPA max
and min replica configuration, autoscaling policies, etc.
These collectors are disabled by default, you have to start the server
with the `--scaling-schedule` flag to enable it. Remember to deploy the CRDs
`ScalingSchedule` and `ClusterScalingSchedule` and allow the service
account used by the server to read, watch and list them.

View File

@ -0,0 +1,119 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.5.0
creationTimestamp: null
name: clusterscalingschedules.zalando.org
spec:
group: zalando.org
names:
kind: ClusterScalingSchedule
listKind: ClusterScalingScheduleList
plural: clusterscalingschedules
singular: clusterscalingschedule
scope: Cluster
versions:
- name: v1
schema:
openAPIV3Schema:
description: ClusterScalingSchedule describes a cluster scoped time based
metric to be used in autoscaling operations.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: ScalingScheduleSpec is the spec part of the ScalingSchedule.
properties:
schedules:
description: Schedules is the list of schedules for this ScalingSchedule
resource. All the schedules defined here will result on the value
to the same metric. New metrics require a new ScalingSchedule resource.
items:
description: Schedule is the schedule details to be used inside
a ScalingSchedule.
properties:
date:
description: Defines the starting date of a OneTime schedule.
It has to be a RFC3339 formated date.
format: date-time
type: string
durationMinutes:
description: The duration in minutes that the configured value
will be returned for the defined schedule.
type: integer
period:
description: Defines the details of a Repeating schedule.
properties:
days:
description: The days that this schedule will be active.
items:
description: ScheduleDay represents the valid inputs for
days in a SchedulePeriod.
enum:
- Sun
- Mon
- Tue
- Wed
- Thu
- Fri
- Sat
type: string
type: array
startTime:
description: The startTime has the format HH:MM
pattern: (([0-1][0-9])|([2][0-3])):([0-5][0-9])
type: string
timezone:
description: The location name corresponding to a file in
the IANA Time Zone database, like Europe/Berlin.
type: string
required:
- days
- startTime
- timezone
type: object
type:
description: Defines if the schedule is a OneTime schedule or
Repeating one. If OneTime, date has to be defined. If Repeating,
Period has to be defined.
enum:
- OneTime
- Repeating
type: string
value:
description: The metric value that will be returned for the
defined schedule.
type: integer
required:
- durationMinutes
- type
- value
type: object
type: array
required:
- schedules
type: object
required:
- spec
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []

View File

@ -1,4 +1,4 @@
apiVersion: apiregistration.k8s.io/v1beta1
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1beta1.custom.metrics.k8s.io

View File

@ -28,6 +28,7 @@ spec:
- --prometheus-server=http://prometheus.kube-system.svc.cluster.local
- --skipper-ingress-metrics
- --aws-external-metrics
- --scaling-schedule
env:
- name: AWS_REGION
value: eu-central-1

View File

@ -1,4 +1,4 @@
apiVersion: apiregistration.k8s.io/v1beta1
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1beta1.external.metrics.k8s.io

View File

@ -1,6 +1,6 @@
apiVersion: v2
name: kube-metrics-adapter
version: 0.1.9
version: 0.1.11
description: kube-metrics-adapter helm chart
home: https://github.com/zalando-incubator/kube-metrics-adapter
maintainers:

View File

@ -0,0 +1,119 @@
{{- if .Values.scalingSchedule.enabled }}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.5.0
creationTimestamp: null
name: clusterscalingschedules.zalando.org
spec:
group: zalando.org
names:
kind: ClusterScalingSchedule
listKind: ClusterScalingScheduleList
plural: clusterscalingschedules
singular: clusterscalingschedule
scope: Cluster
versions:
- name: v1
schema:
openAPIV3Schema:
description: ClusterScalingSchedule describes a cluster scoped time based
metric to be used in autoscaling operations.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: ScalingScheduleSpec is the spec part of the ScalingSchedule.
properties:
schedules:
description: Schedules is the list of schedules for this ScalingSchedule
resource. All the schedules defined here will result on the value
to the same metric. New metrics require a new ScalingSchedule resource.
items:
description: Schedule is the schedule details to be used inside
a ScalingSchedule.
properties:
date:
description: Defines the starting date of a OneTime schedule.
It has to be a RFC3339 formated date.
format: date-time
type: string
durationMinutes:
description: The duration in minutes that the configured value
will be returned for the defined schedule.
type: integer
period:
description: Defines the details of a Repeating schedule.
properties:
days:
description: The days that this schedule will be active.
items:
description: ScheduleDay represents the valid inputs for
days in a SchedulePeriod.
enum:
- Sun
- Mon
- Tue
- Wed
- Thu
- Fri
- Sat
type: string
type: array
startTime:
description: The startTime has the format HH:MM
pattern: (([0-1][0-9])|([2][0-3])):([0-5][0-9])
type: string
timezone:
description: The location name corresponding to a file in
the IANA Time Zone database, like Europe/Berlin.
type: string
required:
- days
- startTime
- timezone
type: object
type:
description: Defines if the schedule is a OneTime schedule or
Repeating one. If OneTime, date has to be defined. If Repeating,
Period has to be defined.
enum:
- OneTime
- Repeating
type: string
value:
description: The metric value that will be returned for the
defined schedule.
type: integer
required:
- durationMinutes
- type
- value
type: object
type: array
required:
- schedules
type: object
required:
- spec
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
{{- end}}

View File

@ -1,5 +1,5 @@
{{- if .Values.enableCustomMetricsApi }}
apiVersion: apiregistration.k8s.io/v1beta1
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1beta1.custom.metrics.k8s.io
@ -12,4 +12,4 @@ spec:
insecureSkipTLSVerify: {{ .Values.tls.skipTLSVerify }}
groupPriorityMinimum: 100
versionPriority: 100
{{- end}}
{{- end}}

View File

@ -182,6 +182,9 @@ spec:
{{- if .Values.zmon.tokenName }}
- --zmon-token-name={{ .Values.zmon.tokenName }}
{{- end}}
{{- if .Values.scalingSchedule.enabled }}
- --scaling-schedule
{{- end}}
resources:
limits:
cpu: {{ .Values.resources.limits.cpu }}

View File

@ -1,5 +1,5 @@
{{- if .Values.enableExternalMetricsApi }}
apiVersion: apiregistration.k8s.io/v1beta1
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1beta1.external.metrics.k8s.io

View File

@ -73,6 +73,17 @@ rules:
- get
- list
- watch
{{- if .Values.scalingSchedule.enabled }}
- apiGroups:
- zalando.org
resources:
- clusterscalingschedules
- scalingschedules
verbs:
- get
- list
- watch
{{- end}}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding

View File

@ -0,0 +1,119 @@
{{- if .Values.scalingSchedule.enabled }}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.5.0
creationTimestamp: null
name: scalingschedules.zalando.org
spec:
group: zalando.org
names:
kind: ScalingSchedule
listKind: ScalingScheduleList
plural: scalingschedules
singular: scalingschedule
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: ScalingSchedule describes a namespaced time based metric to be
used in autoscaling operations.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: ScalingScheduleSpec is the spec part of the ScalingSchedule.
properties:
schedules:
description: Schedules is the list of schedules for this ScalingSchedule
resource. All the schedules defined here will result on the value
to the same metric. New metrics require a new ScalingSchedule resource.
items:
description: Schedule is the schedule details to be used inside
a ScalingSchedule.
properties:
date:
description: Defines the starting date of a OneTime schedule.
It has to be a RFC3339 formated date.
format: date-time
type: string
durationMinutes:
description: The duration in minutes that the configured value
will be returned for the defined schedule.
type: integer
period:
description: Defines the details of a Repeating schedule.
properties:
days:
description: The days that this schedule will be active.
items:
description: ScheduleDay represents the valid inputs for
days in a SchedulePeriod.
enum:
- Sun
- Mon
- Tue
- Wed
- Thu
- Fri
- Sat
type: string
type: array
startTime:
description: The startTime has the format HH:MM
pattern: (([0-1][0-9])|([2][0-3])):([0-5][0-9])
type: string
timezone:
description: The location name corresponding to a file in
the IANA Time Zone database, like Europe/Berlin.
type: string
required:
- days
- startTime
- timezone
type: object
type:
description: Defines if the schedule is a OneTime schedule or
Repeating one. If OneTime, date has to be defined. If Repeating,
Period has to be defined.
enum:
- OneTime
- Repeating
type: string
value:
description: The metric value that will be returned for the
defined schedule.
type: integer
required:
- durationMinutes
- type
- value
type: object
type: array
required:
- schedules
type: object
required:
- spec
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
{{- end}}

View File

@ -4,7 +4,7 @@ replicas: 1
registry:
image: registry.opensource.zalan.do/teapot/kube-metrics-adapter
imageTag: v0.1.9
imageTag: v0.1.10
imagePullPolicy: IfNotPresent
service:
@ -92,3 +92,6 @@ resources:
requests:
cpu: 100m
memory: 100Mi
scalingSchedule:
enabled: false

View File

@ -78,6 +78,15 @@ rules:
- get
- list
- watch
- apiGroups:
- zalando.org
resources:
- clusterscalingschedules
- scalingschedules
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding

View File

@ -0,0 +1,119 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.5.0
creationTimestamp: null
name: scalingschedules.zalando.org
spec:
group: zalando.org
names:
kind: ScalingSchedule
listKind: ScalingScheduleList
plural: scalingschedules
singular: scalingschedule
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: ScalingSchedule describes a namespaced time based metric to be
used in autoscaling operations.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: ScalingScheduleSpec is the spec part of the ScalingSchedule.
properties:
schedules:
description: Schedules is the list of schedules for this ScalingSchedule
resource. All the schedules defined here will result on the value
to the same metric. New metrics require a new ScalingSchedule resource.
items:
description: Schedule is the schedule details to be used inside
a ScalingSchedule.
properties:
date:
description: Defines the starting date of a OneTime schedule.
It has to be a RFC3339 formated date.
format: date-time
type: string
durationMinutes:
description: The duration in minutes that the configured value
will be returned for the defined schedule.
type: integer
period:
description: Defines the details of a Repeating schedule.
properties:
days:
description: The days that this schedule will be active.
items:
description: ScheduleDay represents the valid inputs for
days in a SchedulePeriod.
enum:
- Sun
- Mon
- Tue
- Wed
- Thu
- Fri
- Sat
type: string
type: array
startTime:
description: The startTime has the format HH:MM
pattern: (([0-1][0-9])|([2][0-3])):([0-5][0-9])
type: string
timezone:
description: The location name corresponding to a file in
the IANA Time Zone database, like Europe/Berlin.
type: string
required:
- days
- startTime
- timezone
type: object
type:
description: Defines if the schedule is a OneTime schedule or
Repeating one. If OneTime, date has to be defined. If Repeating,
Period has to be defined.
enum:
- OneTime
- Repeating
type: string
value:
description: The metric value that will be returned for the
defined schedule.
type: integer
required:
- durationMinutes
- type
- value
type: object
type: array
required:
- schedules
type: object
required:
- spec
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []

45
go.mod
View File

@ -2,35 +2,32 @@ module github.com/zalando-incubator/kube-metrics-adapter
require (
github.com/NYTimes/gziphandler v1.0.1 // indirect
github.com/aws/aws-sdk-go v1.36.19
github.com/go-openapi/spec v0.20.0
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/aws/aws-sdk-go v1.39.2
github.com/go-openapi/spec v0.20.3
github.com/influxdata/influxdb-client-go v0.2.0
github.com/influxdata/line-protocol v0.0.0-20201012155213-5f565037cbc9 // indirect
github.com/kubernetes-incubator/custom-metrics-apiserver v0.0.0-20201023074945-51cc7b53320e
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/onsi/gomega v1.8.1 // indirect
github.com/prometheus/client_golang v1.9.0
github.com/prometheus/common v0.15.0
github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v0.0.7
github.com/kubernetes-sigs/custom-metrics-apiserver v0.0.0-20201216091021-1b9fa998bbaa
github.com/mailru/easyjson v0.7.7 // indirect
github.com/prometheus/client_golang v1.10.0
github.com/prometheus/common v0.25.0
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.1.3
github.com/spyzhov/ajson v0.4.2
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.7.0
github.com/zalando-incubator/cluster-lifecycle-manager v0.0.0-20180921141935-824b77fb1f84
golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392 // indirect
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/tools v0.0.0-20200204192400-7124308813f3 // indirect
honnef.co/go/tools v0.0.1-2020.1.3 // indirect
k8s.io/api v0.18.14
k8s.io/apimachinery v0.18.14
k8s.io/apiserver v0.18.14
k8s.io/client-go v0.18.14
k8s.io/component-base v0.18.14
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/api v0.20.5
k8s.io/apimachinery v0.20.5
k8s.io/apiserver v0.20.5
k8s.io/client-go v0.20.5
k8s.io/code-generator v0.20.5
k8s.io/component-base v0.20.5
k8s.io/klog v1.0.0
k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6
k8s.io/metrics v0.18.8
k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd
k8s.io/metrics v0.20.5
sigs.k8s.io/controller-tools v0.5.0
)
go 1.15
go 1.16

539
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,23 @@
// +build tools
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// This package imports things required by build scripts, to force `go mod` to see them as dependencies
package tools
import _ "k8s.io/kube-openapi/cmd/openapi-gen"
import (
_ "k8s.io/code-generator"
_ "k8s.io/kube-openapi/cmd/openapi-gen"
_ "sigs.k8s.io/controller-tools/cmd/controller-gen"
)

74
hack/update-codegen.sh Executable file
View File

@ -0,0 +1,74 @@
#!/bin/bash
# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
SRC="github.com"
GOPKG="${SRC}/zalando-incubator/kube-metrics-adapter"
CUSTOM_RESOURCE_NAME="zalando.org"
CUSTOM_RESOURCE_VERSION="v1"
SCRIPT_ROOT="$(dirname "${BASH_SOURCE[0]}")/.."
OUTPUT_BASE="$(dirname "${BASH_SOURCE[0]}")/"
# generate the code with:
# --output-base because this script should also be able to run inside the vendor dir of
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
# instead of the $GOPATH directly. For normal projects this can be dropped.
OUTPUT_PKG="${GOPKG}/pkg/client"
APIS_PKG="${GOPKG}/pkg/apis"
GROUPS_WITH_VERSIONS="${CUSTOM_RESOURCE_NAME}:${CUSTOM_RESOURCE_VERSION}"
echo "Generating deepcopy funcs"
go run k8s.io/code-generator/cmd/deepcopy-gen \
--input-dirs "${APIS_PKG}/${CUSTOM_RESOURCE_NAME}/${CUSTOM_RESOURCE_VERSION}" \
-O zz_generated.deepcopy \
--bounding-dirs "${APIS_PKG}" \
--go-header-file "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
--output-base "$OUTPUT_BASE"
echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}"
go run k8s.io/code-generator/cmd/client-gen \
--clientset-name versioned \
--input-base "" \
--input "${APIS_PKG}/${CUSTOM_RESOURCE_NAME}/${CUSTOM_RESOURCE_VERSION}" \
--output-package "${OUTPUT_PKG}/clientset" \
--go-header-file "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
--output-base "$OUTPUT_BASE"
echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
go run k8s.io/code-generator/cmd/lister-gen \
--input-dirs "${APIS_PKG}/${CUSTOM_RESOURCE_NAME}/${CUSTOM_RESOURCE_VERSION}" \
--output-package "${OUTPUT_PKG}/listers" \
--go-header-file "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
--output-base "$OUTPUT_BASE"
echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
go run k8s.io/code-generator/cmd/informer-gen \
--input-dirs "${APIS_PKG}/${CUSTOM_RESOURCE_NAME}/${CUSTOM_RESOURCE_VERSION}" \
--versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \
--listers-package "${OUTPUT_PKG}/listers" \
--output-package "${OUTPUT_PKG}/informers" \
--go-header-file "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
--output-base "$OUTPUT_BASE"
# hack to make the generated code work with Go module based projects
cp -r "$OUTPUT_BASE/$GOPKG/pkg/apis" ./pkg
cp -r "$OUTPUT_BASE/$GOPKG/pkg/client" ./pkg
rm -rf "${OUTPUT_BASE:?}${SRC}"

View File

@ -12,13 +12,15 @@ const (
customMetricsPrefix = "metric-config."
perReplicaMetricsConfKey = "per-replica"
intervalMetricsConfKey = "interval"
minPodReadyAgeConfKey = "min-pod-ready-age"
)
type AnnotationConfigs struct {
CollectorType string
Configs map[string]string
PerReplica bool
Interval time.Duration
CollectorType string
Configs map[string]string
PerReplica bool
Interval time.Duration
MinPodReadyAge time.Duration
}
type MetricConfigKey struct {
@ -89,6 +91,15 @@ func (m AnnotationConfigMap) Parse(annotations map[string]string) error {
continue
}
if parts[1] == minPodReadyAgeConfKey {
minPodReadyAge, err := time.ParseDuration(val)
if err != nil {
return fmt.Errorf("failed to parse min-pod-ready-age value %s for %s: %v", val, key, err)
}
config.MinPodReadyAge = minPodReadyAge
continue
}
config.Configs[parts[1]] = val
}
return nil

View File

@ -24,10 +24,11 @@ func TestParser(t *testing.T) {
{
Name: "pod metrics",
Annotations: map[string]string{
"metric-config.pods.requests-per-second.json-path/json-key": "$.http_server.rps",
"metric-config.pods.requests-per-second.json-path/path": "/metrics",
"metric-config.pods.requests-per-second.json-path/port": "9090",
"metric-config.pods.requests-per-second.json-path/scheme": "https",
"metric-config.pods.requests-per-second.json-path/json-key": "$.http_server.rps",
"metric-config.pods.requests-per-second.json-path/path": "/metrics",
"metric-config.pods.requests-per-second.json-path/port": "9090",
"metric-config.pods.requests-per-second.json-path/scheme": "https",
"metric-config.pods.requests-per-second.json-path/min-pod-ready-age": "30s",
},
MetricName: "requests-per-second",
MetricType: autoscalingv2.PodsMetricSourceType,

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,6 @@
package zalando
const (
// GroupName is the group name used in this package.
GroupName = "zalando.org"
)

View File

@ -0,0 +1,38 @@
// Package v1 contains API Schema definitions for the zalando v1 API group
// +kubebuilder:object:generate=true
// +groupName=zalando.org
package v1
import (
"github.com/zalando-incubator/kube-metrics-adapter/pkg/apis/zalando.org"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
var (
schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
// AddToScheme applies all the stored functions to the scheme. A non-nil error
// indicates that one function failed and the attempt was abandoned.
AddToScheme = schemeBuilder.AddToScheme
)
// SchemeGroupVersion is the group version used to register these objects.
var SchemeGroupVersion = schema.GroupVersion{Group: zalando.GroupName, Version: "v1"}
// Resource takes an unqualified resource and returns a Group-qualified GroupResource.
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
// addKnownTypes adds the set of types defined in this package to the supplied scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&ScalingSchedule{},
&ClusterScalingSchedule{},
&ScalingScheduleList{},
&ClusterScalingScheduleList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}

View File

@ -0,0 +1,129 @@
package v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// ScalingSchedule describes a namespaced time based metric to be used
// in autoscaling operations.
// +k8s:deepcopy-gen=true
type ScalingSchedule struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ScalingScheduleSpec `json:"spec"`
}
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// ClusterScalingSchedule describes a cluster scoped time based metric
// to be used in autoscaling operations.
// +k8s:deepcopy-gen=true
// +kubebuilder:resource:scope=Cluster
type ClusterScalingSchedule struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ScalingScheduleSpec `json:"spec"`
}
// ScalingScheduleSpec is the spec part of the ScalingSchedule.
// +k8s:deepcopy-gen=true
type ScalingScheduleSpec struct {
// Schedules is the list of schedules for this ScalingSchedule
// resource. All the schedules defined here will result on the value
// to the same metric. New metrics require a new ScalingSchedule
// resource.
Schedules []Schedule `json:"schedules"`
}
// Schedule is the schedule details to be used inside a ScalingSchedule.
// +k8s:deepcopy-gen=true
type Schedule struct {
Type ScheduleType `json:"type"`
// Defines the details of a Repeating schedule.
// +optional
Period *SchedulePeriod `json:"period,omitempty"`
// Defines the starting date of a OneTime schedule. It has to
// be a RFC3339 formated date.
// +optional
Date *ScheduleDate `json:"date,omitempty"`
// The duration in minutes that the configured value will be
// returned for the defined schedule.
DurationMinutes int `json:"durationMinutes"`
// The metric value that will be returned for the defined schedule.
Value int `json:"value"`
}
// Defines if the schedule is a OneTime schedule or
// Repeating one. If OneTime, date has to be defined. If Repeating,
// Period has to be defined.
// +kubebuilder:validation:Enum=OneTime;Repeating
type ScheduleType string
const (
OneTimeSchedule ScheduleType = "OneTime"
RepeatingSchedule ScheduleType = "Repeating"
)
// SchedulePeriod is the details to be used for a Schedule of the
// Repeating type.
// +k8s:deepcopy-gen=true
type SchedulePeriod struct {
// The startTime has the format HH:MM
// +kubebuilder:validation:Pattern="(([0-1][0-9])|([2][0-3])):([0-5][0-9])"
StartTime string `json:"startTime"`
// The days that this schedule will be active.
Days []ScheduleDay `json:"days"`
// The location name corresponding to a file in the IANA
// Time Zone database, like Europe/Berlin.
Timezone string `json:"timezone"`
}
// ScheduleDay represents the valid inputs for days in a SchedulePeriod.
// +kubebuilder:validation:Enum=Sun;Mon;Tue;Wed;Thu;Fri;Sat
type ScheduleDay string
const (
SundaySchedule ScheduleDay = "Sun"
MondaySchedule ScheduleDay = "Mon"
TuesdaySchedule ScheduleDay = "Tue"
WednesdaySchedule ScheduleDay = "Wed"
ThursdaySchedule ScheduleDay = "Thu"
FridaySchedule ScheduleDay = "Fri"
SaturdaySchedule ScheduleDay = "Sat"
)
// ScheduleDate is a RFC3339 representation of the date for a Schedule
// of the OneTime type.
// +kubebuilder:validation:Format="date-time"
type ScheduleDate string
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ScalingScheduleList is a list of namespaced scaling schedules.
// +k8s:deepcopy-gen=true
type ScalingScheduleList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ScalingSchedule `json:"items"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ScalingScheduleList is a list of cluster scoped scaling schedules.
// +k8s:deepcopy-gen=true
type ClusterScalingScheduleList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ScalingSchedule `json:"items"`
}

Some files were not shown because too many files have changed in this diff Show More