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

fix: Transform ObjectExistsWithSize into GetAttributes #14329

Merged
merged 12 commits into from
Oct 2, 2024

Conversation

DylanGuedes
Copy link
Contributor

@DylanGuedes DylanGuedes commented Oct 1, 2024

What this PR does / why we need it:

  • Transform our ObjectExistsWithSize API into GetAttributes to conform with the existing Thanos API.
  • Fix we not returning the size when we should on our s3 implementation of ObjectSize
  • Fix we not returning false, nil to ObjectExists when the only error seen is a NotFound. If someone calls ObjectExists it should return false, nil to a NotExist error, instead of false, err

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • Title matches the required conventional commits format, see here
    • Note that Promtail is considered to be feature complete, and future development for logs collection will be in Grafana Alloy. As such, feat PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • For Helm chart changes bump the Helm chart version in production/helm/loki/Chart.yaml and update production/helm/loki/CHANGELOG.md and production/helm/loki/README.md. Example PR
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

@DylanGuedes DylanGuedes requested a review from a team as a code owner October 1, 2024 11:21
@CLAassistant
Copy link

CLAassistant commented Oct 1, 2024

CLA assistant check
All committers have signed the CLA.

Dylan Guedes and others added 2 commits October 1, 2024 10:42
- We're not correctly returning the size of the file when there's no error
@DylanGuedes DylanGuedes force-pushed the return-size-correctly-s3-api branch from 82cdd4b to dcc914e Compare October 1, 2024 13:42
@pull-request-size pull-request-size bot added size/L and removed size/M labels Oct 1, 2024
@DylanGuedes DylanGuedes changed the title fix: Fix ObjectExistsWithSize s3 implementation not returning size correctly fix: Transform ObjectExistsWithSize into ObjectSize Oct 1, 2024
@DylanGuedes DylanGuedes changed the title fix: Transform ObjectExistsWithSize into ObjectSize fix: Transform ObjectExistsWithSize into GetAttributes Oct 1, 2024
Copy link
Collaborator

@JoaoBraveCoding JoaoBraveCoding left a comment

Choose a reason for hiding this comment

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

Small nits, overall lgtm! Thank you for this!

Comment on lines 72 to 75
if err != nil {
return false, err
}
return true, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

To make it consistent across the different implementations

Suggested change
if err != nil {
return false, err
}
return true, nil
return err == nil, err

Comment on lines 129 to 132
if err != nil {
return false, err
}
return true, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

To make it consistent across the different implementations

Suggested change
if err != nil {
return false, err
}
return true, nil
return err == nil, err

Comment on lines 397 to 401
if err != nil {
return false, err
}
return true, nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

To make it consistent across the different implementations

Suggested change
if err != nil {
return false, err
}
return true, nil
}
return err == nil, err

Comment on lines 131 to 134
if err != nil {
return false, err
}
return true, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

To make it consistent across the different implementations

Suggested change
if err != nil {
return false, err
}
return true, nil
return err == nil, err

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's super fair but I found a problem with the approach I was following so I had to rewrite everything. I should only return an error if the error isn't NotFound. Not all clients support it which is ok but some of them support it so the rewrite was necessary to keep the old behavior.

return b.objectAttributes(ctx, objectKey, "azure.GetAttributes")
}

func (b *BlobStorage) objectAttributes(ctx context.Context, objectKey, source string) (client.ObjectAttributes, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: IIUC using a different source is just going to create a different metric? Does it make sense to separate calls to this function into separate metrics?
My suggestion would be to just drop the source parameter, if I'm understanding the code correctly

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, the idea is to allow disambiguation between GetAttributes and ObjectExists where it is possible to do it. Loki isn't using GetAttributes so this shouldn't cause any problems but if you're using Loki's API for doing something, having this separation will help your application separating what is leading the object storage requests.

@DylanGuedes DylanGuedes merged commit 2f56f50 into main Oct 2, 2024
60 checks passed
@DylanGuedes DylanGuedes deleted the return-size-correctly-s3-api branch October 2, 2024 16:51
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.

4 participants