Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(#580): adds traffic and tags information to revision list #581

Merged
merged 1 commit into from
Jan 10, 2020

Conversation

maximilien
Copy link
Contributor

@maximilien maximilien commented Dec 20, 2019

Fixes #580

Proposed Changes

  • adds traffic information of revision as an annotation in revision list
  • adds tags information of revision as an annotation in revision list
  • show traffic and tags when listing revisions

With this change, invocation of kn revision list will look like:

➜  client git:(issue580) ✗ ./kn revision list
Using kn config file: /Users/maximilien/.kn/config.yaml
NAME                  SERVICE       GENERATION   AGE   CONDITIONS   READY   TRAFFIC   TAGS    REASON
twitter-fn-ycybl-1    twitter-fn    26           28d   3 OK / 4     True    100%
summary-fn-hwkll-31   summary-fn    20           23d   3 OK / 4     True    50%       async
summary-fn-qwfdb-1    summary-fn    19           23d   3 OK / 4     True    50%       sync
watson-fn-wxpyf-15    watson-fn     15           28d   3 OK / 4     True    100%
hello-world-tndhb-2   hello-world   2            28d   3 OK / 4     True    100%

➜  client git:(issue580) ✗ ./kn revision list -s summary-fn
Using kn config file: /Users/maximilien/.kn/config.yaml
NAME                  SERVICE      GENERATION   AGE   CONDITIONS   READY   TRAFFIC   TAGS    REASON
summary-fn-hwkll-31   summary-fn   20           23d   3 OK / 4     True    50%       async
summary-fn-qwfdb-1    summary-fn   19           23d   3 OK / 4     True    50%       sync

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Dec 20, 2019
@maximilien
Copy link
Contributor Author

/ok-to-test

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 20, 2019
@daisy-ycguo
Copy link
Member

/test pull-knative-client-integration-tests

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some minor change requests, othewise looks good. Thank you !

pkg/kn/commands/revision/list.go Outdated Show resolved Hide resolved

traffic, tags := trafficForRevision(revision.Name, service)
revision.Annotations[RevisionTrafficAnnotation] = fmt.Sprintf("%d%%", traffic)
revision.Annotations[RevisionTagsAnnotation] = strings.Join(tags, ",")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid modifying the revision here by e.g. using a map keyed by revision name ? Imagine if someone later would introduce such annotations for real (so that you would override it here). Also 'misusing' an object by writing to it in a pure read-only use case is not architectural sound.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought of that, however, the revision is not modified permanently. Only temporarily to hold values that frankly belongs to it. These modified revision objects are in memory and are never seen by 'anyone' else other than the user that invoked the command.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid modifying the revision here by

+1

We can use trafficForRevision in printRevision to fetch the traffic and tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read my comment @navidshaikh it does not modify the revision except in memory which makes the rest of the code super clean

Copy link
Collaborator

@navidshaikh navidshaikh Dec 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I think this information doesn't belong to Revision and we shouldn't piggyback this data onto Revision.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I think this information doesn't belong to Revision and we shouldn't piggyback this data onto Revision.

It does at least when using the revision list. See why I opened this issue in the first place. It comes from the need to see this information and not having to have to show the details of the service and parsing the out to find the data. This is my feedback from real usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Imagine someone would print out the full object somewhere in between, like in a kn revision list --verbose or something. You will see artifical annotations here).

kn revision list --verbose call does not exist. If we decide to do it we can easily filter out the annotations or better flag them as such. Which I'd be happy to also do here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree since annotations are meant to do things like that. However, I am happy to hear suggestions on how else to do it?

That's where I disagree, i.e. that annotations are used for volatile information which never gets persisted ;-). But maybe we could at least agree that listing revisions is a read-only operation and could be implemented with immutable objects that don't allow mutating operations? Why should we break that without a need ?

kn revision list --verbose call does not exist. If we decide to do it we can easily filter out the annotations or better flag them as such. Which I'd be happy to also do here.

That's not really the point, whether this feature exists or not as its just an illustrative example. When you say one can easily add a filter, that is a bad smell, too, to use another hack to fix the previous hack.

Not sure whether I could convince you that keeping certain architectural constraints even when they are not enforced today is a good thing. So let's merge them at let me make an alternative suggestion in the next PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether I could convince you that keeping certain architectural constraints even when they are not enforced today is a good thing.

That's not the part that I disagree with.

That's where I disagree, i.e. that annotations are used for volatile information which never gets persisted ;-).

Yup, that's the conundrum. It's the use of annotations. For me, I feel that this is a good use since the attributes I am adding traffic and tags are not really "features" of the Service nor the Revision but of both. There are synthesized from and belong to the association between Service and Revision, in my view.

So let's merge them at let me make an alternative suggestion in the next PR.

OK cool. Look forward to it. Hopefully it's not a significant change since that was where I was headed until this approach. But maybe I am missing some easy trick... Happy to learn.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK cool. Look forward to it. Hopefully it's not a significant change since that was where I was headed until this approach. But maybe I am missing some easy trick... Happy to learn.

I have to apologize a bit :) Ideally I would use classical "view object" used for printing. But the printer framework we are using insist on runtime.Object. To implement those is even more hackish than adding to the annotations (I already was there before I returned back to your approach, which definitely is the better in this particular case). So I suggest indeed to stick to this technique for tunneling purposes (if we would have the printing of a list in our hands, its trivial to change with a revisionInfo object containing the revision + tags,traffic from the service).

However, my point is illustrated quite nicely what happens at the moment, when you are doing a kn revision list -o yaml. This includes, in YAML, the temporary annotations. This is incorrect as these annotations are not part of the revision. We can fix that, but in this initial PR it was overlooked. Something similar can happen in the future, too. Hopefully not, but anybody touching this code needs to be aware of this particular usage of volatile information attached to an otherwise persisted object.

So, there is no easy trick. Life is complicated ;-)

@maximilien maximilien force-pushed the issue580 branch 2 times, most recently from 102541c to df045ee Compare December 20, 2019 20:41
Copy link
Collaborator

@navidshaikh navidshaikh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should re-group the traffic and tags column next to SERVICE for eg:

➜  client git:(df045ee0) ✗ ./kn revision list
NAME           SERVICE   TRAFFIC   TAGS    GENERATION   AGE   CONDITIONS   READY   REASON
test-wrvjj-1   test      100%      v1,v2   1            31m   3 OK / 4     True    


traffic, tags := trafficForRevision(revision.Name, service)
revision.Annotations[RevisionTrafficAnnotation] = fmt.Sprintf("%d%%", traffic)
revision.Annotations[RevisionTagsAnnotation] = strings.Join(tags, ",")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid modifying the revision here by

+1

We can use trafficForRevision in printRevision to fetch the traffic and tags.

@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/kn/commands/revision/human_readable_flags.go 95.0% 95.5% 0.5
pkg/kn/commands/revision/list.go 85.2% 86.2% 1.0

@maximilien
Copy link
Contributor Author

We should re-group the traffic and tags column next to SERVICE for eg:

➜  client git:(df045ee0) ✗ ./kn revision list
NAME           SERVICE   TRAFFIC   TAGS    GENERATION   AGE   CONDITIONS   READY   REASON
test-wrvjj-1   test      100%      v1,v2   1            31m   3 OK / 4     True    

Done

@maximilien
Copy link
Contributor Author

@navidshaikh this is ready to merge IMO.

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment. As it seems that we disagree (see last comment) here on the implementation, let's merge it and let me make an alternative proposal (which might also illustrate my point a bit better).

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 10, 2020
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: maximilien, rhuss

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rhuss
Copy link
Contributor

rhuss commented Jan 10, 2020

Looks like a flaky error

customresourcedefinition.apiextensions.k8s.io/services.serving.knative.dev created
error: unable to recognize "https://storage.googleapis.com/knative-nightly/serving/latest/serving.yaml": no matches for kind "Image" in version "caching.internal.knative.dev/v1alpha1"
Installing the rest of serving components from https://storage.googleapis.com/knative-nightly/serving/latest/serving.yaml
customresourcedefinition.apiextensions.k8s.io/images.caching.internal.knative.dev unchanged

/retest

@navidshaikh
Copy link
Collaborator

/retest

timeout: service 'hello' not ready after 600 seconds

@rhuss
Copy link
Contributor

rhuss commented Jan 10, 2020

/retest

@knative-prow-robot knative-prow-robot merged commit ac2170c into knative:master Jan 10, 2020
var service *v1alpha1.Service
var serviceName string
for _, revision := range revisionList.Items {
if serviceName == "" || revision.Labels[serving.ServiceLabelKey] != serviceName {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just working on an followup PR, but wanna leave some extra comments): It is by no means guaranteed that revisions from the list are sorted according to service. Better store in a map for latter referral.

Please don't fix I'm on it.

@maximilien maximilien deleted the issue580 branch January 10, 2020 21:43
coryrc pushed a commit to coryrc/client that referenced this pull request May 14, 2020
dsimansk pushed a commit to dsimansk/client that referenced this pull request Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kn revision list does not show traffic and tagging details
7 participants