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

Add and update metric status #5395

Merged
merged 9 commits into from
Sep 6, 2019
Merged

Conversation

taragu
Copy link
Contributor

@taragu taragu commented Sep 4, 2019

/lint

Fixes #5304

Proposed Changes

  • Currently, there's no status field for metric so there's no way of knowing the readiness of metric objects. This PR adds and updates the metric status.

Release Note

NONE

/cc @nak3
/cc @jonjohnsonjr

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Sep 4, 2019
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 4, 2019
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@taragu: 0 warnings.

In response to this:

/lint

Fixes #5304

Proposed Changes

  • Currently, there's no status field for metric so there's no way of knowing the readiness of metric objects. This PR adds the metric status and propagate it to pod autoscaler.

Release Note

NONE

/cc @nak3
/cc @jonjohnsonjr

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@knative-prow-robot knative-prow-robot added area/API API objects and controllers area/autoscale labels Sep 4, 2019
pkg/reconciler/autoscaling/kpa/scaler.go Outdated Show resolved Hide resolved
pkg/reconciler/autoscaling/kpa/kpa_test.go Outdated Show resolved Hide resolved
pkg/apis/autoscaling/v1alpha1/pa_lifecycle.go Outdated Show resolved Hide resolved
@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 4, 2019
@taragu taragu changed the title Add and propagate metric status to autoscaler Add and update metric status Sep 4, 2019
Copy link
Contributor

@vagababov vagababov left a comment

Choose a reason for hiding this comment

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

metric_lifecycle.go needs unit tests.

pkg/reconciler/metric/metric.go Outdated Show resolved Hide resolved
pkg/apis/autoscaling/v1alpha1/metric_lifecycle.go Outdated Show resolved Hide resolved
pkg/reconciler/autoscaling/reconciler.go Outdated Show resolved Hide resolved
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 5, 2019
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if e, a := tc.isReady, tc.status.IsReady(); e != a {
t.Errorf("%q expected: %v got: %v", tc.name, e, a)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ready = %v, want: %v
no need to log tc.name, t.Run takes care of that.

@@ -63,7 +64,9 @@ type MetricSpec struct {
}

// MetricStatus reflects the status of metric collection for this specific entity.
type MetricStatus struct{}
type MetricStatus struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, we can just do type MetricStatus duckv1beta1.Status?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vagababov I'm not sure if type alias is appropriate here, since it's for gradual code repair while moving a type between packages during large-scale refactoring

if err := r.collector.CreateOrUpdate(metric); err != nil {
if err.Error() == "failed to get endpoints" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather we switched to typed errors (e.g. collector.ErrFailedGetEndpoints) and then check equality.

apitest.CheckConditionOngoing(m.duck(), MetricConditionReady, t)

const wantReason = "reason"
const wantMessage = "the error message"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const wantMessage = "the error message"
const (
wantReason = "reason"
wantMessage = "the error message"
)

}

ms.MarkMetricReady()

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove extra lines from all the places

func TestMetricGetGroupVersionKind(t *testing.T) {
r := &Metric{}
want := schema.GroupVersionKind{
Group: "autoscaling.internal.knative.dev",
Copy link
Contributor

@savitaashture savitaashture Sep 6, 2019

Choose a reason for hiding this comment

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

I'd rather use autoscaling.InternalGroupName

var (
// errFailedGetEndpoints specifies the error returned by scraper when it fails to
// get endpoints.
errFailedGetEndpoints = "failed to get endpoints"
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just errFailedGetEndpoints = errors.New("failed to get endpoints")?

@@ -131,7 +141,7 @@ func urlFromTarget(t, ns string) string {
func (s *ServiceScraper) Scrape() (*StatMessage, error) {
readyPodsCount, err := s.counter.ReadyCount()
if err != nil {
return nil, errors.Wrap(err, "failed to get endpoints")
return nil, errors.Wrap(err, errFailedGetEndpoints)
Copy link
Contributor

Choose a reason for hiding this comment

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

log and return canned error

var (
// errFailedGetEndpoints specifies the error returned by scraper when it fails to
// get endpoints.
errFailedGetEndpoints = errors.New("failed to get endpoints")
Copy link
Contributor

Choose a reason for hiding this comment

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

If you make these public, then the methods below will not be required
and you can just check the errors for equality since you are returning the exact object.

This is usually how go does this kind of stuff (e.g. https://golang.org/pkg/io/#pkg-variables)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool!! That's good to know

@@ -261,15 +261,17 @@ func newCollection(metric *av1alpha1.Metric, scraper StatsScraper, logger *zap.S
case <-scrapeTicker.C:
message, err := c.getScraper().Scrape(logger)
if err != nil {
copy := *(metric.DeepCopy())
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't dereference here

wait.PollImmediate(10*time.Millisecond, 2*time.Second, func() (bool, error) {
got = test.metric.Status.Status
return equality.Semantic.DeepEqual(got, test.expectedMetricStatus), nil
wait.PollImmediate(10*time.Millisecond, 5*time.Second, func() (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why did we change time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this is not necessary. Just removed

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-serving-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/autoscaler/collector.go 95.6% 96.9% 1.3
pkg/autoscaler/stats_scraper.go 91.2% 89.8% -1.4
pkg/reconciler/metric/metric.go 92.3% 93.3% 1.0

Copy link
Contributor

@vagababov vagababov left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 6, 2019
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: taragu, vagababov

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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 6, 2019
@taragu
Copy link
Contributor Author

taragu commented Sep 6, 2019

/test pull-knative-serving-unit-tests

@knative-prow-robot knative-prow-robot merged commit 2130d9f into knative:master Sep 6, 2019
@nak3
Copy link
Contributor

nak3 commented Sep 7, 2019

Does this patch work well? I think UpdateStatus() needs to be called somewhere, but I cannot find it anywhere.

@vagababov
Copy link
Contributor

/reopen
Nope.

@knative-prow-robot
Copy link
Contributor

@vagababov: Failed to re-open PR: state cannot be changed. The pull request cannot be reopened.

In response to this:

/reopen
Nope.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

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. area/API API objects and controllers area/autoscale cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Add status field to metrics object
7 participants