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

[patch] [agent-NGT, sidecar] Improve S3 backup/recover behavior #556

Merged
merged 37 commits into from
Jul 22, 2020

Conversation

rinx
Copy link
Contributor

@rinx rinx commented Jul 7, 2020

Signed-off-by: Rintaro Okamura rintaro.okamura@gmail.com

Description:

sidecar now watches only changes in {index_path}/metadata.json and it triggers a backup process.
the post_stop_timeout has different meaning compared to before.
in the post-stop process, sidecar also watches changes in {index_path}/metadata.json, and if there's changes in it, it creates a backup in S3. however, there's no changes within post_stop_timeout, also it starts to create a backup.

7/13:
metadata.json now contains "is_invalid" field that indicates the backup files are valid or not.
if it is true, sidecar will not upload the backup files and terminate itself immediately.

Related Issue:

#503 #551 #581

How Has This Been Tested?:

nothing

Environment:

  • Go Version: 1.14.3
  • Docker Version: 19.03.8
  • Kubernetes Version: 1.18.2
  • NGT Version: 1.11.5

Types of changes:

  • Bug fix [type/bug]
  • New feature [type/feature]
  • Add tests [type/test]
  • Security related changes [type/security]
  • Add documents [type/documentation]
  • Refactoring [type/refactoring]
  • Update dependencies [type/dependency]
  • Update benchmarks and performances [type/bench]
  • Update CI [type/ci]

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Checklist:

  • I have read the CONTRIBUTING document.
  • I have checked open Pull Requests for the similar feature or fixes?
  • I have added tests and benchmarks to cover my changes.
  • I have ensured all new and existing tests passed.
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly.

@pull-assistant
Copy link

pull-assistant bot commented Jul 7, 2020

Score: 0.95

Best reviewed: commit by commit


Optimal code review plan (10 warnings)

     ♻️ not to overwrite existing backup files

     ✅ update tests for internal/compress

🔧 add default_pool_size option / add internal/json package

.../agent/core/ngt/service/ngt.go 80% changes removed in ♻️ add defaul...

     ✨ Add metadata package to write agent metadata when the index...

✨ revise file.Open interface

.../agent/core/ngt/service/ngt.go 45% changes removed in ♻️ refactor i...

     ✅ fix file test

     ✅ fix json tests

     🎨 use filepath.Join

✨ revise watching method for ngt index backup files

...r/service/observer/observer.go 60% changes removed in ♻️ revise obs...

     ✅ remove dps from ngt_test

✨ kill own process when NGT index cannot be loaded within tim...

.../agent/core/ngt/service/ngt.go 59% changes removed in ♻️ revise age...

🚨 fix deepsource issues

.../agent/core/ngt/service/ngt.go 50% changes removed in ♻️ refactor i...

     🚚 move internal/json -> internal/encoding/json

[agent-NGT] refactor pkg/agent/core/service using FOP (#566)

...ent/core/ngt/usecase/agentd.go 43% changes removed in ♻️ pass cfg s...

     ♻️ refactor initNGT func

     ✅ update

     ✨ add isValid flag to metadata

     💚 revise fetch depth for run test workflow

♻️ use isInvalid because it should be default to false

internal/metadata/metadata.go 50% changes removed in 🎨 fix tag format...

     🎨 fix tag format

     ♻️ fix poststop logic

✨ add Escape() method to errgroup

...nternal/errgroup/group_test.go 49% changes removed in Revert ":sparkles: a...

internal/errgroup/group.go 58% changes removed in Revert ":sparkles: a...

     📦 add *.containers field

     Revert ":package: add *.containers field"

     ✅ update

Revert ":white_check_mark: update"

internal/errgroup/group.go 44% changes removed in Revert ":sparkles: a...

Revert ":sparkles: add Escape() method to errgroup"

.../agent/core/ngt/service/ngt.go 83% changes removed in ♻️ exit safel...

     ♻️ exit safely using goroutine

     🚚 move internal/metadata -> pkg/agent/internal/metadata

     ♻️ add defaultPoolSize const

     ♻️ pass cfg struct to agent service

     🐳 fix dockerfiles

     ♻️ add watch_enabled & auto_backup_enabled options

     ✅ fix tests

     ♻️ revise agent-ngt codes based on suggestions

     ✅ update

     ♻️ revise observer poststop

Powered by Pull Assistant. Last update 7382a36 ... 25d315b. Read the comment docs.

@vdaas-ci
Copy link
Collaborator

vdaas-ci commented Jul 7, 2020

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 💌 /changelog - add changelog comment
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • /rebase - rebase master

@codecov
Copy link

codecov bot commented Jul 7, 2020

Codecov Report

Merging #556 into master will decrease coverage by 0.03%.
The diff coverage is 9.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #556      +/-   ##
==========================================
- Coverage   11.75%   11.71%   -0.04%     
==========================================
  Files         404      407       +3     
  Lines       20928    21207     +279     
==========================================
+ Hits         2460     2485      +25     
- Misses      18205    18445     +240     
- Partials      263      277      +14     
Impacted Files Coverage Δ
internal/compress/gob.go 26.19% <0.00%> (-1.31%) ⬇️
internal/compress/gzip.go 26.98% <0.00%> (-7.02%) ⬇️
internal/compress/lz4.go 36.36% <0.00%> (-5.31%) ⬇️
internal/compress/zstd.go 29.50% <0.00%> (-5.79%) ⬇️
internal/config/config.go 15.78% <ø> (ø)
internal/config/sidecar.go 0.00% <ø> (ø)
internal/errors/file.go 0.00% <0.00%> (ø)
internal/errors/ngt.go 0.00% <ø> (ø)
pkg/agent/core/ngt/service/ngt.go 0.00% <0.00%> (ø)
pkg/agent/core/ngt/usecase/agentd.go 0.00% <0.00%> (ø)
... and 14 more

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 ec75fba...25d315b. Read the comment docs.

@github-actions github-actions bot added team/set SET team size/XXL and removed size/L labels Jul 7, 2020
@rinx rinx force-pushed the refactor/agent-ngt-sidecar/improve-s3-backup-behavior branch from 0d3560f to acbcb8f Compare July 8, 2020 00:54
@github-actions github-actions bot added size/XL and removed size/XL labels Jul 8, 2020
@rinx rinx force-pushed the refactor/agent-ngt-sidecar/improve-s3-backup-behavior branch from 833f237 to daa7c7c Compare July 8, 2020 06:02
@vdaas-ci
Copy link
Collaborator

vdaas-ci commented Jul 8, 2020

[WARNING:INTCFG] Changes in interal/config may require you to change Helm charts. Please check.

internal/core/ngt/option.go Outdated Show resolved Hide resolved
pkg/agent/core/ngt/service/ngt.go Show resolved Hide resolved
pkg/agent/core/ngt/service/ngt.go Outdated Show resolved Hide resolved
@rinx rinx changed the title [agent-NGT, sidecar] Improve S3 backup/recover behavior [patch] [agent-NGT, sidecar] Improve S3 backup/recover behavior Jul 9, 2020
@rinx rinx force-pushed the refactor/agent-ngt-sidecar/improve-s3-backup-behavior branch from e796e86 to 6544d39 Compare July 9, 2020 06:19
internal/json/json.go Outdated Show resolved Hide resolved
internal/json/json.go Outdated Show resolved Hide resolved
internal/json/json.go Outdated Show resolved Hide resolved
internal/json/json.go Outdated Show resolved Hide resolved
internal/json/json.go Outdated Show resolved Hide resolved
}
if n.dvc == nil {
n.dvc = new(vcaches)
func (n *ngt) initNGT(opts ...core.Option) (err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
Function 'initNGT' is too long (103 > 60) (funlen)

if err != nil {
return err
}
defer f.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
Error return value of f.Close is not checked (errcheck)


eg, _ := errgroup.New(ctx)
eg.Go(safety.RecoverFunc(func() (err error) {
select {
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
S1000: should use a simple channel send/receive instead of select with a single case (gosimple)

pkg/agent/core/ngt/service/ngt.go Outdated Show resolved Hide resolved
pkg/agent/core/ngt/service/ngt.go Outdated Show resolved Hide resolved
@rinx rinx force-pushed the refactor/agent-ngt-sidecar/improve-s3-backup-behavior branch from 0c68d8a to ca58ce7 Compare July 9, 2020 06:39
@rinx rinx marked this pull request as ready for review July 9, 2020 06:57
@rinx rinx requested review from kpango, vankichi and hlts2 July 9, 2020 06:58
@rinx rinx marked this pull request as draft July 9, 2020 07:16
rinx added 7 commits July 20, 2020 07:02
Signed-off-by: Rintaro Okamura <rintaro.okamura@gmail.com>
Signed-off-by: Rintaro Okamura <rintaro.okamura@gmail.com>
Signed-off-by: Rintaro Okamura <rintaro.okamura@gmail.com>
Signed-off-by: Rintaro Okamura <rintaro.okamura@gmail.com>
Signed-off-by: Rintaro Okamura <rintaro.okamura@gmail.com>
Signed-off-by: Rintaro Okamura <rintaro.okamura@gmail.com>
Signed-off-by: Rintaro Okamura <rintaro.okamura@gmail.com>
@vdaas-ci vdaas-ci force-pushed the refactor/agent-ngt-sidecar/improve-s3-backup-behavior branch from 121eec7 to a8db9be Compare July 20, 2020 07:02
@vdaas-ci
Copy link
Collaborator

[FORMAT] Updating license headers and formatting go codes triggered by rinx.

charts/vald/values.yaml Outdated Show resolved Hide resolved
@@ -25,7 +25,7 @@ jobs:
- name: Check out code.
uses: actions/checkout@v1
with:
fetch-depth: 1
fetch-depth: 10
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please teach me about this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sometimes this workflow fails on master branch because of failing to fetch commits.
https://github.com/vdaas/vald/actions/runs/164399448
To prevent this, it is better to fetch not only the latest commit.

internal/core/ngt/option.go Outdated Show resolved Hide resolved
}

if !n.inMem && len(cfg.IndexPath) != 0 {
n.path = cfg.IndexPath
if in, ok := n.indexing.Load().(bool); !ok || in {
Copy link
Contributor

Choose a reason for hiding this comment

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

when we call New method, indexing valueable always contains nil.
so I think the following is better 🤔

Suggested change
if in, ok := n.indexing.Load().(bool); !ok || in {
n.indexing.Store(false)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! i'll fix it.

Signed-off-by: Rintaro Okamura <rintaro.okamura@gmail.com>
@rinx
Copy link
Contributor Author

rinx commented Jul 21, 2020

@hlts2 @vankichi @kpango I've just fixed the codes according to your review comments.
Please review again 🙏

Signed-off-by: Rintaro Okamura <rintaro.okamura@gmail.com>
internal/core/ngt/option.go Show resolved Hide resolved
internal/core/ngt/option.go Show resolved Hide resolved
internal/core/ngt/option.go Show resolved Hide resolved
pkg/agent/core/ngt/service/ngt_test.go Show resolved Hide resolved
Signed-off-by: Rintaro Okamura <rintaro.okamura@gmail.com>
Copy link
Contributor

@hlts2 hlts2 left a comment

Choose a reason for hiding this comment

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

LGTM

@kpango kpango merged commit 031d78c into master Jul 22, 2020
@kpango kpango deleted the refactor/agent-ngt-sidecar/improve-s3-backup-behavior branch July 22, 2020 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants