Commit Graph

71 Commits

Author SHA1 Message Date
Lance Liu e863db0344
Remove key in tags to reduce metrics count (#1494)
* Remove key in tags to reduce metrics count
Issue: https://github.com/knative/serving/issues/8609

Signed-off-by: Lance Liu <xuliuxl@cn.ibm.com>

* remove tag key for OpenCensus

Signed-off-by: Lance Liu <xuliuxl@cn.ibm.com>
2020-07-15 01:29:32 -07:00
Victor Agababov 16eea5bd5b
remove the ResourceLock field from the pkg/LE (#1482)
we only use a single possible way, so no need to have, parse and validate
field that is in effectg a constant.
2020-07-14 09:15:18 -07:00
Matt Moore a81727701f
Enable leader election by default. (#1476)
* Enable HA by default.

This consolidates the core of sharedmain around the new leaderelection logic, which will now be **enabled by default**.

This can now be disabled with `--disable-ha` or by passing `sharedmain.WithHADisabled(ctx)` to `sharedmain.MainWithConfig`.

* vagababov comments, build failure

* Open an issue for enabledComponents removal.

* Move the configmap watcher startup.

This race was uncovered by the chaos duck on knative/serving!  When we have enabled a feature flag, e.g. multi-container, and the webhook pods are restarted, there is a brief window where the webhook is up and healthy before the configmaps have synchronized and the new webhook pod realizes the feature is enabled.

* Drop the import alias
2020-07-13 12:43:18 -07:00
Markus Thömmes a92c682188
Add an option to skip automated status updates in a reconciler. (#1456)
* Add an option to skip automated status updates in a reconciler.

This option is necessary to be able to create reconcilers like Serving's labeler, that is purely adding labels to resources. If that fails, the new automated observed generation handling changes the status and that gets written to the API currently, which is not desired.

* Flip the bool.
2020-06-30 08:02:29 -07:00
Markus Thömmes 09d5e09da8
Assorted linting fixes. (#1443) 2020-06-24 12:11:27 -07:00
Weston Haught 602857dcc5
add self to aliases and add reviewers to OWNERS (#1409)
* add self to aliases and add reviewers to OWNERS

* fix typo
2020-06-22 12:30:27 -07:00
Matt Moore 7df8fc5d77
Implement the first wave of per-reconciler leaderelection. (#1301)
* Implement the first wave of per-reconciler leaderelection.

Detailed design: https://docs.google.com/document/d/1i_QHjQO2T3SNv49xjZLWlivcc0UvZN1Tbw2NKxThkyM/edit#
Issue: https://github.com/knative/pkg/issues/1181

* Feedback from vagababov

* Feedback from yanweiguo

* Drop IsLeaderFor from the LeaderAware interface.

* Moar vagababov nits

* dprotaso feedback

* Add issue comment, error return

* Incorporate dprotaso test feedback
2020-06-18 19:07:25 -07:00
Antoine Cotten 82fe339a5e
Implement Unwrap() and Is() for permanentErrors (#1363)
* Implement Unwrap() for permanentErrors

* Implement Is() for permanentErrors
2020-06-02 13:27:18 -07:00
Yanwei Guo 19b1d7b64d
Add a helper func to set a default metric config for unit tests (#1263)
* do not record for empty metric config

* Revert "do not record for empty metric config"

This reverts commit 539a5e4dbb.

* add a comment

* fix typo

* fix tests

* revert

* revert tests

* revert

* fix conflicts

* one more test file
2020-05-07 21:11:45 -07:00
Victor Agababov 66f1d63f10
Fix logging around pkg (#1310)
- use more performant functions (mostly remove formatters were possible)
- move zap.Error() to the call site, rather than creating a new sugared logger with a key attached (not cheap)
- fix *w usages where the key was not provided.
2020-05-07 15:00:45 -07:00
Yanwei Guo 66c1551b08
Use helper func from metricstest package for the unit test (#1268)
* do not record for empty metric config

* Revert "do not record for empty metric config"

This reverts commit 539a5e4dbb.

* use metricstest package for test
2020-05-07 12:04:45 -07:00
Markus Thömmes 0e0f650dfa
Fix deprecation comment. (#1279) 2020-05-04 00:13:43 -07:00
Shashwathi 93be3f499d
Add ability to override controller agent name (#1240)
* Add the ability to override controller agent name

- controller can set agent name via context. If nothing is set then
controller falls back to default controller agent name

* Check if context name is not nil and can be casted to string before returning.

* Create EventRecorder after we determine the controller agent name

* Address comments

Signed-off-by: Andrew Su <asu@pivotal.io>

* Remove check for if recorder is nil

Co-authored-by: Andrew Su <asu@pivotal.io>
2020-05-02 10:00:43 -07:00
Markus Thömmes 47137cdc30
Explicitly name controller filters. (#1257)
* Explicitly name controller filters.

Everytime I read the generic "Filter" or "FilterGroupVersionKind" my brain needs to do an extra roundtrip to realize that this actually filters on the **controller** having that GVK/GK. This adds new functions that explictly state that to avoid that roundtrip.

Old functions are just deprecated so this can be rolled out without a downstream break.

* Rename after review.
2020-04-29 10:18:42 -07:00
Markus Thömmes d29cf98a77
Assorted linting fixes. (#1249)
* Remove unused code.

* Use raw strings to avoid escaping.

* Remove unneeded type conversions.

* Preallocate slices where possible.

* Use semantic equality in psbinding reconciler.
2020-04-28 08:20:51 -07:00
Matt Moore 7b6e21a57a
Change StartAll to take context. (#1247)
* Change StartAll to take context.

This has bugged me since we started using `ctx`, which containers a `stopCh` of sorts as `Done()`.  This is somewhat for consistency, but by using `ctx` explicitly we enable ourselves to take advantage of more contextual information.

I did a quick scan of call sites and the good news is that the `sharedmain` change should be the place through which the vast majority of calls occur, however, the one outlier here is the KPA which calls this manually.  I will stage a PR to manually import pkg into serving to fix this once this lands.

* Add a Run shim for back-compat
2020-04-25 16:21:49 -07:00
Markus Thömmes 6103dd9b71
Add a controller option to specify a custom finalizer name. (#1230) 2020-04-22 14:55:40 -07:00
Ville Aikas 4e57475bc8
add EnqueueNamespaceOf (#1217)
* add EnqueueNamespaceOf

* correct log error msg
2020-04-10 18:11:07 -07:00
Scott Nichols d93ce78496
[Reconciler Generators] Adding support for configStore.ToContext (#1085)
* Support optional config maps.

* document configmap stores

* whitespace.

* optionsFns

* review

* check for nil.

* zero trust imports.
2020-02-12 16:10:35 -08:00
Dave Protasowski e3d924ba00
allow filtering on schema.GroupKind (#1080)
* allow filtering on schema.GroupKind

In addition deprecated usage of Filter with the introduction of
FilterGroupVersionKind

* reduce nesting & simplify boolean logic
2020-02-12 12:12:18 -08:00
Victor Agababov 41aec11a3c
Use new RecordBatch method to join metric reporting (#1029)
* Use new RecordBatch method to join metric reporting

* review
2020-02-03 16:27:30 -08:00
Maisem Ali 64ed9fcf84 add EnqueueSentinel to pkg/controller (#841)
* add EnqueueSentinel to pkg/controller

* address comments
2019-11-04 16:22:20 -08:00
Markus Thömmes 56c2594e4f Assorted linting fixes. (#840)
* Remove unused code.

* Remove unneeded loops.

* Remove unneeded Printf calls.

* Use time.Since instead of time.Now().Sub.

* Remove unused values.

* Rename error variable according to conventions.

* Return error last.

* Simplify array allocations.

* Remove leaky ticker.

* Remove Yoda conditions.

* Remove deprecated function to talk to GKE.

* Remove dot import.

* Remove empty critical section and replace with a channel operation.

* Add linter directives to explicitly state wanted weirdness.

* Update deps.

* Fix broken line.
2019-11-01 12:49:12 -07:00
Matt Moore 809ce573e4 Add FilterByName for cluster-scoped resources. (#816)
This is a precursor to reconciling named webhook configurations, and largely a copy of `FilterByNameAndNamespace`.
2019-10-28 10:41:42 -07:00
Slavomir Kaslev 29642b017b Add RunInformers function (#758)
Add RunInfomers which is similar to the StartInformers function but allows for
users to for informers to finish running.

This function will be mainly used in tests to fix the race described in
knative/serving#5351
2019-10-14 10:02:32 -07:00
Markus Thömmes de32ec136d Fix a subtle bug with cluster scoped entities. (#708) 2019-09-20 12:26:07 -07:00
Markus Thömmes 4a790dd36c Plumb through a structured key, keep current behavior. (#703)
* Plumb through a structured key, keep current behavior.

* Rename variable.
2019-09-20 06:52:05 -07:00
Matt Moore e4ac97c252 Update our dependency on K8s libs to 1.15.3 (#686)
With a minimum K8s version of 1.14 (starting in 0.10), 1.15.3 puts us in the center of the +/-1 version window of support.
2019-09-18 13:36:48 -07:00
Matt Moore 3c828cf99f Hook into two other Kubernetes metric subsystems. (#682)
This adds logic to hook into two other metric systems:
1. `cache.SetReflectorMetricsProvider`, which doesn't seem hooked up in Kubernetes yet, but would theoretically give us metrics about the mechanisms underpinning informers.
2. `metrics.Register`, which hooks us into the rest client infrastructure to give us metrics about low-level API server calls.

Fixes: https://github.com/knative/pkg/issues/679
Fixes: https://github.com/knative/pkg/issues/680
2019-09-16 10:46:43 -07:00
Matt Moore ecb98001f2 Implement workqueue.MetricsProvider (#678)
The kubernetes workqueue provides a facility for collecting metrics by registering a workqueue.MetricsProvider
via workqueue.SetProvider.

This change implements that interface to expose the workqueue metrics into opencensus.

This is loosely based on some work started by @grantr [here](https://github.com/kubernetes-sigs/controller-runtime/compare/master...grantr:opencensus-replace#diff-bb94124aff8d568cb4e82854c7d44fd1)

Fixes: https://github.com/knative/pkg/issues/522
2019-09-16 09:55:41 -07:00
savitaashture 7b67118970 Use tag.MustNewKey instead tag.NewKey (#654) 2019-09-10 18:23:29 -07:00
Victor Agababov 7db4b798fb Do not enqueue items when the queue is shut down (#652)
* Do not enqueu (and log) if we're shutting down

* Wait for queue to empty before terminate and other restrictions

We need to stop enqueueing stuff when queue is shuitting down since this causes panics in our tests.
So

1. wait for queue to empty before shutting down
2. do not enqueue stuff for global reconciliation if the queue is shutting down (this exhibits races in global resync tests)
3. do not enqueue on error, since while the erroneous object was being processed the queue might have terminated

/assign mattmoor
2019-09-09 18:07:11 -07:00
Matt Moore 1a3a36a996 Rework how we GlobalResync. (#597)
* Rework how we GlobalResync.

This consolidates the logic for how we do GlobalResyncs in a few ways:
1. Remove SendGlobalUpdates and replace it with FilteredGlobalResync.
2. Have GlobalResync go through the FilteredGlobalResync with a tautological predicate.
3. Change the way we enqueue things during a global resync to avoid flooding the system
   by using EnqueueAfter and wait.Jitter to stagger how things are queued.

The background for this is that when I started to benchmark reconciliation of a large
number of resources we'd see random large stalls like [this](https://mako.dev/run?run_key=4882560844824576&~dl=1&~cl=1&~rl=1&~rvl=1&~il=1&~sksl=1&~pal=1)
fairly consistently.  Looking at the logs, these stalls coincide with incredibly deep
work queues due to global resyncs triggers by configmap notifications. When I disabled
global resyncs the spikes [went away](https://mako.dev/run?run_key=4975897060835328&~dl=1&~cl=1&~rl=1&~rvl=1&~il=1&~sksl=1&~pal=1).

To mitigate the huge pile-up due to the global resync we use `wait.Jitter` to stagger how
things are enqueued with a `maxFactor` of the length of the store.  This also seems to
[keep things flowing](https://mako.dev/run?run_key=5701802099998720&~dl=1&~cl=1&~rl=1&~rvl=1&~il=1&~sksl=1&~pal=1),
although we will possibly need to tune things further.

* Update comment to mention the delay.
2019-08-24 21:23:13 -07:00
Victor Agababov 74c5d67ea0 Fix the issues pointed out by staticcheck (#541)
* Fix the issues pointed out by staticcheck

* review fix
2019-07-23 13:13:36 -07:00
mattmoor-sockpuppet 1864f499dc golang format tools (#497)
Produced via:
  `gofmt -s -w $(find -path './vendor' -prune -o -type f -name '*.go' -print))`
  `goimports -w $(find -name '*.go' | grep -v vendor)`
/assign @mattmoor
2019-06-27 07:37:08 -07:00
Matt Moore 222dd25986 Migrate pkg to use the knative.dev/pkg import path (#489)
* Manual changes.

* scripted changes.
2019-06-26 13:02:06 -07:00
Matt Moore 2f853a1fdc Let the stats reporter tests run with -count=N (#486) 2019-06-23 20:12:02 -07:00
Matt Moore 7538724784 Stabilize the controller unit tests. (#482) 2019-06-23 17:16:00 -07:00
Matt Moore c6f03fa600 Push the event recorder stuff into knative/pkg (#443) 2019-06-06 07:35:40 -07:00
Adriano Cunha c0132d9dde Update OWNERS to use OWNERS_ALIASES (#422) 2019-05-29 20:04:33 -07:00
Matt Moore 985bff446d Simplify the default controller.Impl constructor. (#427)
A while back we added a "StatsReporter" argument to `controller.NewImpl`,
but in serving every callsite of this is passing:
```
controller.NewImpl(r, logger, "my-string", MustNewStatsReporter("my-string", logger))
```

Where `MustNewStatsReporter` is just a form of knative/pkg's `controller.NewStatsReporter`
that logs fatally when an error is returned.  It is notable that Serving's logic has been
duplicated to both Build and Eventing.

There are a handful of changes here:
1. Move MustNewStatsReporter into knative/pkg
2. Expose the current interface as NewImplWithStats
3. Drop the StatsReporter from NewImpl and default to `MustNewStatsReporter()`

This is a breaking change for downstream repositories, but should make their callsites universally simpler.
2019-05-28 13:16:31 -07:00
Matt Moore d1ccfd6652 This upstreams a useful helper from serving. (#428)
In serving we have `reconciler.Handler` that wraps a handler function
(e.g. `Enqueue`) in the `cache.ResourceEventHandlerFuncs`.  This pattern
was becoming pervasive, so this simpler handler dramatically reduced our
boilerplate.
2019-05-27 23:21:29 -07:00
Matt Moore aae68ba9e0 Add methods for attaching resync duration to context. (#426)
Also adds a method for tracker leases, which should be a multiple of the resync period.
2019-05-26 23:44:29 -07:00
mattmoor-sockpuppet 34792a92ce golang format tools (#419)
Produced via:
  `gofmt -s -w $(find -path './vendor' -prune -o -type f -name '*.go' -print))`
  `goimports -w $(find -name '*.go' | grep -v vendor)`
2019-05-18 10:35:26 -07:00
leo james 7b196cff46 add trace id (#405)
* add trace id

* using with list

* add comment
2019-05-16 07:14:22 -07:00
Ville Aikas 5e4512dcb2 Add Filter function by name/namespace (#414) 2019-05-14 13:53:32 -07:00
Victor Agababov c3f131538a add addafter method that permits enqueueing the objects themselves (#408) 2019-05-08 16:14:37 -07:00
Victor Agababov f23f58d373 Expose the EnqueueKeyAfter function on the controller (#402)
This is needed for the positive handoff, so that we can enqueue
the KPA after we received the positive answer from the activator
but still want to have buffer time to make sure the network
changes propagate everywhere.
2019-05-02 17:16:34 -07:00
Nghia Tran 590eb946f1 Add a version of GlobalResync that calls an event handler. (#381)
* Add a version of GlobalResync that calls an event handler.

This allows impl to apply filtering and queuing logic of their own,
instead of calling Enqueue() for everything.

* Fix typo in doc comment.
2019-04-10 13:33:59 -07:00
Matt Moore 7735348150 Add some helpers to reduce boilerplate in controller binaries. (#335)
* Add some helpers to reduce boilerplate in controller binaries.

* Incorporate feedback from Victor.

* Fix a couple test data races.
2019-03-23 10:57:48 -07:00