Skip to content

Detailed documentation for ServingState semantics #645

Closed

Description

@mattmoor

This covers documenting the detailed semantics of ServingState.

In particular, I am interested in:

  1. ServingState is desired state, how do I check the observed state?
  2. How does Active -> {Reserve,Retired} affect Revision conditions (e.g. Ready)? Are new conditions needed?
  3. How do we ensure that the activator is wired up before resources are torn down?

To be clear, I expect that for some of the above additional development work will be necessary, and I'd like to reach a point where we're updating docs either before or alongside the code.

Related (pre-req): #644

Activity

  1. added
    kind/doc
    area/API
    on Apr 13, 2018
  2. added this to the milestone on Apr 13, 2018
  3. self-assigned this
    on Apr 14, 2018
  4. mattmoor commented on Apr 14, 2018

    @mattmoor
    ContributorAuthor

    Lifecycle of a Revision (today)

    Before proposing an alternative, I wanted to sketch my understanding of the current thinking today, and where I believe there are weaknesses we need to address. This may be wholly inaccurate, so please LMK where my understanding is flawed.

    Event: First deploy

    The Revision is created in an Active state. Deployment and Service are created. When the Service’s Endpoint contains an entry, the Revision is declared “Ready”.

    Event: Scaled to Zero

    After a period of inactivity, the autoscaler puts the Revision into the “ServingState” of “Reserve”.

    The Route controller observes this state change, and redirects the ingress to an “Activator” component. Keying off of the same signal, the Revision controller deletes the underlying K8s resources. There is a race here.

    Despite the endpoint having no entries the Revision won’t leave a “Ready” state because of this logic (IIUC). No information is conveyed to indicate that the Revision has been actually scaled to zero and is unprepared to receive traffic.

    Event: Scaled from Zero

    Traffic arrives for our Revision, but hits the activator. The activator looks up the Revision that should be receiving the traffic and sets its “ServingState” to “Active”.

    However, because “Active” is indistinguishable from “Reserve”, the activator has no meaningful way of knowing when the Revision has recreated its elements (and they are ready).


    Again, this may be a completely flawed representation of the plan, but it reflects my understanding of the plan, and at a minimum highlights our need to better document the semantics of these fields!

    I will follow up with a proposal, that I believe addresses some of these problems next.

  5. mattmoor commented on Apr 14, 2018

    @mattmoor
    ContributorAuthor

    Lifecycle of a Revision (proposed)

    This proposal is intended to address some of the weaknesses above, including the race and the surfacing of “observed” serving state.

    Event: First deploy

    (same)

    Event: Scaled to Zero

    After a period of inactivity, the autoscaler puts the Revision into the “ServingState” of “ActiveReserve” (a new state).

    The Route controller watches for Revisions entering the “ActiveReserve” state and updates their Ingress to go through the activator instead of referencing them directly. Once done, the Route controller puts the Revision into a “Reserve” state.

    The Revision controller will take no action on entering the “ActiveReserve” state; from its perspective the Revision is still active and may receive traffic at any time. Upon entering the “Reserve” state, the Revision Controller will remove some portion of the underlying k8s resources.

    At this point, we need to convey that the Revision is no longer “Ready”, so we will surface the following conditions via the Revision’s status:

    status:
      conditions:
      - type: Ready
        status: False
      - type: Reserve
        status: True
        reason: NoTraffic
        message: This revision was put into a reserve state due to inactivity.
    

    Event: Scaled from Zero

    Traffic arrives for our Revision, but hits the activator. The activator looks up the Revision that should be receiving the traffic and sets its “ServingState” to “Active”.

    The activator then watches the Revision, waiting for it to re-enter a Ready state, at which point the queued traffic is forwarded.

    Event: Removed from Route

    When the Revision is removed from the Route’s Spec, the Route will first remove the Revision’s service from its ingress rules, so that it stops receiving traffic. Then the Route puts the Revision into a “Retired” state.

    At this point, we need to convey that the Revision is no longer “Ready”, so we will surface the following conditions via the Revision’s status:

    status:
      conditions:
      - type: Ready
        status: False
      - type: Retired
        status: True
        reason: NotRoutable
        message: This revision is no longer reachable via a Route.
    

    Event: Added to Route

    When the Revision is added (back) to the Route’s Spec, the Route must first ensure that the Revision is “Ready”. If the Revision is not in an “Active” state, the Route will change it and wait for it to report itself “Ready”.


    If this informal sketch makes sense, I will write it up as more official documentation including updates to the existing specification where appropriate.

    cc @josephburnett @vaikas-google @evankanderson @grantr @cooperneil

  6. grantr commented on Apr 16, 2018

    @grantr
    Contributor

    The Route controller observes this state change, and redirects the ingress to an “Activator” component. Keying off of the same signal, the Revision controller deletes the underlying K8s resources. There is a race here.

    To make sure I understand: the race is between the parallel actions of redirecting the ingress and deleting the resources. If resources are deleted before the ingress is changed, requests will be lost.

    After a period of inactivity, the autoscaler puts the Revision into the “ServingState” of “ActiveReserve” (a new state).

    This feels like a status to me. "ActiveReserve" is temporary, not a desired end state. To avoid hijacking this issue, I've created #669 describing an alternative approach that IMO creates a better separation between status and spec. In the meantime, I'm 👍 on the proposal here to remove the race condition.


    🤔 What should happen for a route with a zero-percent traffic rule? For example:

    spec:
      traffic:
      - revisionName: foo
        percent: 100
      - revisionName: bar
        percent: 0

    Is the second traffic rule removed from the spec? Is bar considered to be unrouted? Does it go into the Retired or Reserved state?

  7. mattmoor commented on Apr 17, 2018

    @mattmoor
    ContributorAuthor

    This feels like a status to me. "ActiveReserve" is temporary, not a desired end state.

    Like replicas: N on a ReplicaSet it's often both. The auto-scaler observes an idle Active revision, and configures it's desired state to be ActiveReserve (similar to lame duck). Once the activator switch is made, the Route controller sets it's desired state to Reserve, which may take time to realize.

    When the Revision is ultimately removed from routing, the transition to Retired is also an expression of desired state, and the Revision controller must clean up.

  8. akyyy commented on Apr 17, 2018

    @akyyy
    Contributor

    @mattmoor, @josephburnett

    In Lifecycle of a Revision (Today),
    Event: Scaled to Zero part:
    "Despite the endpoint having no entries the Revision won’t leave a “Ready” state because of this logic (IIUC). No information is conveyed to indicate that the Revision has been actually scaled to zero and is unprepared to receive traffic."

    This is not what we're doing now. When the k8s resources are deleted, the revision is marked with this RevisionCondition, so it's not ready.
    reason: Inactive
    status: "False"
    type: Ready

    This is the code:
    https://github.com/elafros/elafros/blob/0be70191e5021bfeb8e29593490e5d0a2c24d8cc/pkg/controller/revision/revision.go#L635

  9. mattmoor commented on Apr 17, 2018

    @mattmoor
    ContributorAuthor

    thanks @akyyy.

    I hadn't looked to see that we were manually updating the status. I think we still need a Ready: True => False path when our Service's Endpoint becomes empty, but that isn't necessary for auto-scaling.

  10. mattmoor commented on Apr 25, 2018

    @mattmoor
    ContributorAuthor

    I think we're punting this to get solved by some of the work @grantr and @glyn are driving, which is certainly going to extend into M5.

    /assign @grantr

  11. modified the milestones: , on Apr 25, 2018
  12. 9 remaining items

  13. mattmoor commented on Jun 15, 2018

    @mattmoor
    ContributorAuthor

    @josephburnett I'm assigning this to you to drive as the lead for autoscaling.

    I am concerned with enabling the activator by default in our current state because:

    1. We have a known race condition going Active -> Reserve, and
    2. We haven't clearly documented the impact of Reserve on the Revision lifecycle.

    Can you take the AI to sketch this model, update docs/spec/..., and drive fixing the lifecycle?

  14. akyyy commented on Jun 15, 2018

    @akyyy
    Contributor

    @mattmoor Could you please elaborate on the race condition with 1->0 scaling?

  15. mattmoor commented on Jun 19, 2018

    @mattmoor
    ContributorAuthor

    The race is that we have two processes keying off of the same signal: Revision.ServingState = Reserve.

    1. The route controller starts to splice in the activator, and
    2. The revision controller starts to tear down K8s resources.

    We should not do the latter until the former is complete, or we risk dropping traffic that arrives while the resources are gone, but before the activator is in place.

  16. akyyy commented on Jun 19, 2018

    @akyyy
    Contributor

    @mattmoor That is addressed in #1251, where we route the traffic to activator service first during condition "Deactivating", and then tear down k8s resource when it's "Inactive".

  17. mattmoor commented on Jun 19, 2018

    @mattmoor
    ContributorAuthor

    @akyyy Let's set up some time to discuss this because we should not be predicating on cond.Reason. You are using cond.Reason as we should be using cond.Type, which is what this issue is all about: designing, specifying and implementing a solution at the level of condition Types (or through other API mechanics).

  18. josephburnett commented on Jun 19, 2018

    @josephburnett
    Contributor
  19. akyyy commented on Jun 20, 2018

    @akyyy
    Contributor

    We need to have a better story to tell the states of a revision. e.g.

    if (cond.Reason == "Inactive" && cond.Status == corev1.ConditionFalse) ||

    We're using both RevisionCondition status and reason.

  20. akyyy commented on Jun 20, 2018

    @akyyy
    Contributor

    We should consider deleting "Retired" serving state from revisions since it's not used.

  21. self-assigned this
    on Jun 20, 2018
  22. markusthoemmes commented on Oct 26, 2018

    @markusthoemmes
    Contributor

    @mattmoor Can this be closed, since we deprecated ServingState in its entirety?

  23. added a commit that references this issue on Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/APIarea/autoscalekind/doc

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions