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

faster refresh capabilities #743

Merged
merged 1 commit into from
Dec 10, 2020

Conversation

captainroy-hy
Copy link
Collaborator

to fix #629

Signed-off-by: roywang seiwy2010@gmail.com

@@ -10,6 +16,8 @@ import (
cmdutil "github.com/oam-dev/kubevela/pkg/commands/util"
"github.com/oam-dev/kubevela/pkg/plugins"
"github.com/oam-dev/kubevela/pkg/utils/system"

hashstructure "github.com/mitchellh/hashstructure/v2"
)

type refreshStatus string
Copy link
Collaborator

Choose a reason for hiding this comment

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

我见到比较多的 type name 首字母是大写的,请确认一下:)

@codecov
Copy link

codecov bot commented Dec 8, 2020

Codecov Report

Merging #743 (a961b00) into master (bffd43f) will decrease coverage by 0.05%.
The diff coverage is 29.41%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #743      +/-   ##
==========================================
- Coverage   34.45%   34.40%   -0.06%     
==========================================
  Files          92       92              
  Lines        8053     8130      +77     
==========================================
+ Hits         2775     2797      +22     
- Misses       4981     5025      +44     
- Partials      297      308      +11     
Flag Coverage Δ
unittests 34.40% <29.41%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/commands/env.go 42.73% <0.00%> (ø)
pkg/commands/system.go 0.00% <0.00%> (ø)
pkg/commands/workloads.go 0.00% <0.00%> (ø)
...ev/v1alpha2/core/scopes/healthscope/healthscope.go 87.37% <ø> (ø)
pkg/commands/refresh.go 14.19% <29.87%> (+14.19%) ⬆️
pkg/commands/traits.go 73.33% <66.66%> (+0.91%) ⬆️
...plicationconfiguration/applicationconfiguration.go 78.51% <0.00%> (-0.83%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bffd43f...a961b00. Read the comment docs.

timestamp := strconv.FormatInt(time.Now().Unix(), 10)
tmpDir := filepath.Join(capDir, ".tmp")
timeFilePath := filepath.Join(tmpDir, ".lastRefresh")
exist, _ := system.CreateIfNotExist(tmpDir)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we delete the dir later?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since it's in the dir .vela/capabilities, I think it's okay to be deleted along with .vela/capabilities if necessary.

@@ -397,6 +397,7 @@ func (p PeerHealthConditions) MergePeerWorkloadsConditions(basic *WorkloadHealth
// copy to keep idempotent
peerHCs := make(PeerHealthConditions, len(p))
copy(peerHCs, p)
//nolint:makezero
Copy link
Collaborator

Choose a reason for hiding this comment

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

我懂了 makezero 的含义了,为了更明确,要不要换一个名字,比如 slice-make-zero-length?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes... it's an ambiguous name, but makezero is the name of the linter, and I have already commented it in .golangci-lint.yml

. "github.com/onsi/gomega"
)

func TestCheckRefreshInterval(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

please don't use ginkgo for pure unit-test. It's hard to maintain. We prefer ginkgo only when the test need K8s environment.

We prefer table driven test for normal unit-test, you can refer to https://dave.cheney.net/2019/05/07/prefer-table-driven-tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

got it.

@@ -21,14 +29,27 @@ const (
deleted refreshStatus = "Deleted"
)

const (
refreshInterval = time.Minute
Copy link
Collaborator

Choose a reason for hiding this comment

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

please make the default time to be 5min

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

got it, shall we add a flag to enforce refresh, just for dev convenience?

Copy link
Collaborator

Choose a reason for hiding this comment

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

shall we add a flag to enforce refresh, just for dev convenience?

Sure, but users may not be aware of that. That could be very useful for development and demo.

@@ -10,6 +16,8 @@ import (
cmdutil "github.com/oam-dev/kubevela/pkg/commands/util"
"github.com/oam-dev/kubevela/pkg/plugins"
"github.com/oam-dev/kubevela/pkg/utils/system"

hashstructure "github.com/mitchellh/hashstructure/v2"
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit

report[unchanged] = append(report[unchanged], newCap)
break
}
}
if types.EqualCapability(oldCap, newCap) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we still need this when we have already use cachedHash ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I think we can remove it. It seems unlikely to delete the cache file by someone.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

After reconsideration, I think it's okay to keep this part in case of cached hash is missing.

@captainroy-hy captainroy-hy force-pushed the faster-refresh branch 3 times, most recently from b3a219e to c6216a1 Compare December 9, 2020 10:42
Copy link
Collaborator

@wonderflow wonderflow left a comment

Choose a reason for hiding this comment

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

lgtm

@wonderflow
Copy link
Collaborator

please resolve conflicts

Signed-off-by: roywang <seiwy2010@gmail.com>
@wonderflow wonderflow merged commit f48aba6 into kubevela:master Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] faster 'vela workloads / vela traits' command
3 participants