-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
There was a problem hiding this 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.
8ef72a4
to
010e315
Compare
There was a problem hiding this 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.
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) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
pkg/reconciler/metric/metric.go
Outdated
if err := r.collector.CreateOrUpdate(metric); err != nil { | ||
if err.Error() == "failed to get endpoints" { |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const wantMessage = "the error message" | |
const ( | |
wantReason = "reason" | |
wantMessage = "the error message" | |
) |
} | ||
|
||
ms.MarkMetricReady() | ||
|
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
df7ea55
to
0adf580
Compare
pkg/autoscaler/stats_scraper.go
Outdated
var ( | ||
// errFailedGetEndpoints specifies the error returned by scraper when it fails to | ||
// get endpoints. | ||
errFailedGetEndpoints = "failed to get endpoints" |
There was a problem hiding this comment.
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")
?
pkg/autoscaler/stats_scraper.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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
e9fdda4
to
07b3bd8
Compare
pkg/autoscaler/stats_scraper.go
Outdated
var ( | ||
// errFailedGetEndpoints specifies the error returned by scraper when it fails to | ||
// get endpoints. | ||
errFailedGetEndpoints = errors.New("failed to get endpoints") |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
fc42144
to
42ec3a3
Compare
pkg/autoscaler/collector.go
Outdated
@@ -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()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't dereference here
pkg/autoscaler/collector_test.go
Outdated
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
The following is the coverage report on pkg/.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
[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 |
/test pull-knative-serving-unit-tests |
Does this patch work well? I think |
/reopen |
@vagababov: Failed to re-open PR: state cannot be changed. The pull request cannot be reopened. In response to this:
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. |
/lint
Fixes #5304
Proposed Changes
Release Note
/cc @nak3
/cc @jonjohnsonjr