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

Feat: add Baidu Cloud BOS as storage backends for Loki #4788 #5848

Merged
merged 15 commits into from
May 5, 2022

Conversation

arcosx
Copy link
Contributor

@arcosx arcosx commented Apr 9, 2022

What this PR does / why we need it:

Hi all, I plan to add Baidu Cloud (one of the Chinese cloud vendors, also named as Baidu BCE) BOS (object storage, like s3) as one of the storage backends for Loki. In China many users don't use cloud vendors like amazon and google cloud. Adding Baidu Cloud BOS as a backend storage will help more Chinese users to try Loki.

some links:

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Checklist

  • Documentation added
  • Tests updated
  • Add an entry in the CHANGELOG.md about the changes.

@arcosx arcosx changed the title Feat: add Baidu AI Cloud as storage backends for Loki #4788 Feat: add Baidu BCE BOS as storage backends for Loki #4788 Apr 9, 2022
@arcosx arcosx force-pushed the feat/baidubce-new branch 2 times, most recently from 69e4188 to 33af522 Compare April 9, 2022 17:02
@arcosx arcosx changed the title Feat: add Baidu BCE BOS as storage backends for Loki #4788 Feat: add Baidu Cloud BOS as storage backends for Loki #4788 Apr 9, 2022
Signed-off-by: arcosx <arcosx@outlook.com>
@owen-d
Copy link
Member

owen-d commented Apr 12, 2022

Thanks for the PR! I don't have much time at the moment, but I'll see if we can get another to review it in the meantime.

Copy link
Collaborator

@trevorwhitney trevorwhitney left a comment

Choose a reason for hiding this comment

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

LGTM! Great work, thanks for the contribution. Looks like this very closely follows our patterns for S3. Just a few small questions and changes.

We don't have an environment to test this in. I assume you do? Please keep us in the loop on how this is working in that env and follow up with any bugs you see there.

Thanks!

@@ -483,6 +483,9 @@ storage:
# Configures backend rule storage for a local file system directory.
[local: <local_storage_config>]

# Configures backend rule storage for Baidu BCE BOS.
Copy link
Collaborator

Choose a reason for hiding this comment

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

should add an option to the comment above on type as well to include bos

Copy link
Contributor

Choose a reason for hiding this comment

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

# Method to use for backend rule storage (azure, gcs, s3, swift, local).
# CLI flag: -ruler.storage.type
[type: <string> ]

This comment. I agree.

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 was careless, this has been fixed.

go.mod Outdated
@@ -110,6 +110,8 @@ require (
k8s.io/klog v1.0.0
)

require github.com/baidubce/bce-sdk-go v0.9.81
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not an expert around why we have this file organized the way we do, but I imagine we want this in one of the other require sections rather than sitting on it's own?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes! I move it.

@@ -65,6 +67,9 @@ func (cfg *RuleStoreConfig) Validate() error {
if err := cfg.S3.Validate(); err != nil {
return errors.Wrap(err, "invalid S3 Storage config")
}
if err := cfg.BOS.Validate(); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this function always returns nil, why bother calling it here and implenting it as a no-op. We could follow a similar patter with the GCSConfig where we don't call Validate here and therefore don't need to implement it as a no-op. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I delete the function Validate() .You are right.It no need used now.

}

func (cfg *BosStorageConfig) Validate() error {
return nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

see comment above, do we need to implement this as a no-op to satisfy an interface or can we just avoid calling it?

}
for _, content := range listObjectResult.Contents {
// LastModified format 2021-10-28T06:55:01Z
LastModifiedTime, err := time.Parse(time.RFC3339, content.LastModified)
Copy link
Collaborator

Choose a reason for hiding this comment

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

convention is lowerCamelCase for the local variable

Suggested change
LastModifiedTime, err := time.Parse(time.RFC3339, content.LastModified)
lastModifiedTime, err := time.Parse(time.RFC3339, content.LastModified)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}
storageObjects = append(storageObjects, client.StorageObject{
Key: content.Key,
ModifiedAt: LastModifiedTime,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ModifiedAt: LastModifiedTime,
ModifiedAt: lastModifiedTime,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -483,6 +483,9 @@ storage:
# Configures backend rule storage for a local file system directory.
[local: <local_storage_config>]

# Configures backend rule storage for Baidu BCE BOS.
Copy link
Contributor

Choose a reason for hiding this comment

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

# Method to use for backend rule storage (azure, gcs, s3, swift, local).
# CLI flag: -ruler.storage.type
[type: <string> ]

This comment. I agree.

docs/sources/configuration/_index.md Outdated Show resolved Hide resolved
docs/sources/configuration/_index.md Outdated Show resolved Hide resolved
pkg/loki/config_wrapper_test.go Outdated Show resolved Hide resolved
pkg/storage/chunk/client/baidubce/bos_storage_client.go Outdated Show resolved Hide resolved
pkg/storage/chunk/client/baidubce/bos_storage_client.go Outdated Show resolved Hide resolved
Comment on lines 164 to 166
if realErr.Code == ObjectNotFoundErr {
return true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this work? I'm not understanding the link you have above the ObjectNotFoundErr definition, and how will you compare the string ObjectNotFoundErr to an error code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes.It works fine.We can use this error code to represent that the storage object does not exist.I test is no problem.
This page describe it . https://intl.cloud.baidu.com/doc/BOS/s/Ajwvysfpl-en
image

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, can you please include a comment to this link or something similar that shows the struct definition for BceServiceError. I was confused because by default I expect something called error.Code to be an integer type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree with what you said, I think it would be better to return integer error codes here as well.
Now I added comments pointing to its source code.

pkg/storage/factory.go Outdated Show resolved Hide resolved
@arcosx
Copy link
Contributor Author

arcosx commented Apr 19, 2022

Thanks for @trevorwhitney @cstyan guidance, I have a complete test environment on my side, and the following 3-minute video shows the full extent of this feature(The video has sound, but closing it does not affect the viewing), which can be applied on production systems.

Screencast.2022-04-20.00.22.41.mp4

Signed-off-by: arcosx <arcosx@outlook.com>
Copy link
Contributor

@KMiller-Grafana KMiller-Grafana left a comment

Choose a reason for hiding this comment

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

A couple of doc improvements. Thanks.

One of these changes should eventually be propagated to other storage block configuration sections in the docs. For now, we can have the BOS section description have better wording than the other storage section descriptions.

CHANGELOG.md Outdated Show resolved Hide resolved
docs/sources/configuration/_index.md Outdated Show resolved Hide resolved
arcosx and others added 2 commits April 21, 2022 11:28
Co-authored-by: Karen Miller <84039272+KMiller-Grafana@users.noreply.github.com>
Co-authored-by: Karen Miller <84039272+KMiller-Grafana@users.noreply.github.com>
Signed-off-by: arcosx <arcosx@outlook.com>
Copy link
Collaborator

@trevorwhitney trevorwhitney left a comment

Choose a reason for hiding this comment

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

Thanks for making those changes, LGTM!

Copy link
Contributor

@KMiller-Grafana KMiller-Grafana left a comment

Choose a reason for hiding this comment

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

Changes are to correctly specify the product name. Some changes are required for my approval, while others are suggestions that might not be possible given vendored code.

docs/sources/configuration/_index.md Outdated Show resolved Hide resolved
docs/sources/configuration/_index.md Outdated Show resolved Hide resolved
docs/sources/configuration/_index.md Outdated Show resolved Hide resolved
docs/sources/configuration/_index.md Outdated Show resolved Hide resolved
pkg/storage/chunk/client/baidubce/bos_storage_client.go Outdated Show resolved Hide resolved
pkg/storage/chunk/client/baidubce/bos_storage_client.go Outdated Show resolved Hide resolved
pkg/storage/chunk/client/baidubce/bos_storage_client.go Outdated Show resolved Hide resolved
arcosx and others added 7 commits April 27, 2022 11:02
Co-authored-by: Karen Miller <84039272+KMiller-Grafana@users.noreply.github.com>
Co-authored-by: Karen Miller <84039272+KMiller-Grafana@users.noreply.github.com>
Co-authored-by: Karen Miller <84039272+KMiller-Grafana@users.noreply.github.com>
Co-authored-by: Karen Miller <84039272+KMiller-Grafana@users.noreply.github.com>
Co-authored-by: Karen Miller <84039272+KMiller-Grafana@users.noreply.github.com>
Co-authored-by: Karen Miller <84039272+KMiller-Grafana@users.noreply.github.com>
Co-authored-by: Karen Miller <84039272+KMiller-Grafana@users.noreply.github.com>
Copy link
Contributor

@KMiller-Grafana KMiller-Grafana left a comment

Choose a reason for hiding this comment

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

Thank you for making all the changes. This PR looks good from a docs perspective now.

@arcosx
Copy link
Contributor Author

arcosx commented Apr 28, 2022

@owen-d @trevorwhitney @cstyan @KMiller-Grafana Thanks again for reviewing the code ! Can it be merged?

Copy link
Member

@owen-d owen-d left a comment

Choose a reason for hiding this comment

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

Hey, sorry it took so long for me to review this. It looks great!

Thanks for the diligent work during review and the video demo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants