-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Update Firestore and held-back dependencies #21190
Conversation
@zmb3 Did you want backports to v12 on this or wait? Memory fails me. |
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.
@xacrimon, don't forget to remove the updated dependencies from the ignored list in the .github/dependabot.yml
file
@tigrato thanks! I have now run the manual FS tests using the dev API key, missed these as I closed out early yesterday. |
lib/backend/firestore/firestorebk.go
Outdated
mDocs := make(map[string]*firestore.DocumentSnapshot) | ||
for _, doc := range docs { | ||
mDocs[doc.Ref.Path] = doc | ||
} |
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.
This section doesn't seem to be used except for jobs := make([]*firestore.BulkWriterJob, 0, len(mDocs))
.
Probably you wanted to use the mDocs
in the for loop instead of docs?
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.
Huh, do we have a review race condition here perhaps? I did update the loop in that commit to use mDocs. In e7b5f0d
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 don't think we need to consider any race condition here.
Anw, a final nit to avoid ranging a map
// deleteDocuments removes documents from firestore in batches to stay within the
// firestore write limits
func (b *Backend) deleteDocuments(docs []*firestore.DocumentSnapshot) error {
set := make(map[string]struct{})
batch := b.svc.BulkWriter(b.clientContext)
jobs := make([]*firestore.BulkWriterJob, 0, len(docs))
i := 0
for _, doc := range docs {
// Deduplicate documents. The Firestore SDK will error if duplicates are found,
// but existing callers of this functionassume this is valid.
if _, ok := set[doc.Ref.Path]; ok {
continue
}
set[doc.Ref.Path] = struct{}{}
job, err := batch.Delete(doc.Ref)
if err != nil {
return ConvertGRPCError(err)
}
jobs = append(jobs, job)
i++
if i >= commitLimit {
batch.Flush()
}
}
batch.End()
var errs []error
for _, job := range jobs {
if _, err := job.Results(); err != nil {
errs = append(errs, ConvertGRPCError(err))
}
}
return trace.NewAggregate(errs...)
}
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.
Updated, but is there anything bad about ranging a map?
lib/backend/firestore/firestorebk.go
Outdated
mDocs := make(map[string]*firestore.DocumentSnapshot) | ||
for _, doc := range docs { | ||
mDocs[doc.Ref.Path] = doc | ||
} |
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 don't think we need to consider any race condition here.
Anw, a final nit to avoid ranging a map
// deleteDocuments removes documents from firestore in batches to stay within the
// firestore write limits
func (b *Backend) deleteDocuments(docs []*firestore.DocumentSnapshot) error {
set := make(map[string]struct{})
batch := b.svc.BulkWriter(b.clientContext)
jobs := make([]*firestore.BulkWriterJob, 0, len(docs))
i := 0
for _, doc := range docs {
// Deduplicate documents. The Firestore SDK will error if duplicates are found,
// but existing callers of this functionassume this is valid.
if _, ok := set[doc.Ref.Path]; ok {
continue
}
set[doc.Ref.Path] = struct{}{}
job, err := batch.Delete(doc.Ref)
if err != nil {
return ConvertGRPCError(err)
}
jobs = append(jobs, job)
i++
if i >= commitLimit {
batch.Flush()
}
}
batch.End()
var errs []error
for _, job := range jobs {
if _, err := job.Results(); err != nil {
errs = append(errs, ConvertGRPCError(err))
}
}
return trace.NewAggregate(errs...)
}
@tigrato I meant a human/GitHub race condition :) |
45167c1
to
7a1bcc5
Compare
@tigrato I was made aware by a friend that the commit limit is no more using this API (docs seemed to indicate it was, but they are outdated). So I removed those in addition to fixing a test. Can you re-review please? |
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
@rosstimothy Since this is a major API structure switch for how bulk deletes are done, this may need an extra eye during v13 testing. |
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'm a bit late to the party, but adding comments anyway.
Thanks Joel, happy to see this update get merged.
cloud.google.com/go/storage v1.28.0 | ||
github.com/fsouza/fake-gcs-server v1.42.2 | ||
google.golang.org/api v0.103.0 | ||
google.golang.org/genproto v0.0.0-20221201164419-0e50fba7f41c |
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 update api/go.mod too.
WriteResults: []*firestorepb.WriteResult{{ | ||
|
||
resp := &firestorepb.BatchWriteResponse{} | ||
for i := 0; i < len(req.Writes); i++ { |
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.
Suggestion: If you don't need the variable:
for i := 0; i < len(req.Writes); i++ { | |
for _ := range req.Writes { |
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.
for range req.Writes
works too.
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.
Even better ☝️
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.
hold up, when did we get this syntax?
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.
Since forever, I think.
@@ -261,6 +257,14 @@ func TestDeleteDocuments(t *testing.T) { | |||
CreateTime: time.Now(), |
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.
nit: Use for-range above?
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.
The variable i
is actually used in the loop at L252. See L255, always been that way.
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.
Comment is still viable, although certainly not worth a PR.
// We really shouldn't need this, but the Firestore SDK made some unfortunate design | ||
// decisions that make it impossible to set the field of a DocumentRef used for the seemingly | ||
// useless deduplication in the BulkWriter API. | ||
rs := reflect.ValueOf(docs[i].Ref).Elem() | ||
rf := rs.FieldByName("shortPath") | ||
rf = reflect.NewAt(rf.Type(), unsafe.Pointer(rf.UnsafeAddr())).Elem() | ||
rf.SetString(docs[i].Ref.Path) |
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.
What is the consequence of not setting this? Could we get around the reflect block in some other way?
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.
This was already merged due to @rosstimothy adding it to the queue. I was confused by errors for some time in tests for quite some time that didn't crop up in real world testing. As it turns out, the firestore SDK BulkWriter
API we now use assembles batches of changes internally and submits them. Each batch is deduplicated so you can't get two deletes or an edit after a delete in the same batch, so they always succeed. The consequence of this is that it's illegal to delete a document twice with the same BulkWriter.
This would be fine, the test generates an unique ref.Path
right? Well, as it turns out, the SDK does deduplication on an internal hidden variable which represents the path in a smaller encoding. Why? I have no idea. But this is stored in a hidden field that we cannot set easily. If you remove this, you get deduplication errors in the tests, even if the ref.Path
is unique.
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 could not find an alternative way around this easily.
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.
Fair enough, thanks for the explanation.
* update dep * implicit aggregate * fix kind check * remove cring address manip * correct import * invert if * fix rename --------- Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
* update dep * implicit aggregate * fix kind check * remove cring address manip * correct import * invert if * fix rename --------- Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
* [v14] OpenTelemetry Updates (#33523) * Bump go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp Bumps [go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp](https://github.com/open-telemetry/opentelemetry-go-contrib) from 0.42.0 to 0.44.0. - [Release notes](https://github.com/open-telemetry/opentelemetry-go-contrib/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/CHANGELOG.md) - [Commits](open-telemetry/opentelemetry-go-contrib@zpages/v0.42.0...zpages/v0.44.0) --- updated-dependencies: - dependency-name: go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * Bump go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp Bumps [go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp](https://github.com/open-telemetry/opentelemetry-go-contrib) from 0.42.0 to 0.44.0. - [Release notes](https://github.com/open-telemetry/opentelemetry-go-contrib/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/CHANGELOG.md) - [Commits](open-telemetry/opentelemetry-go-contrib@zpages/v0.42.0...zpages/v0.44.0) --- updated-dependencies: - dependency-name: go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * Additional OpenTelemetry updates This updates other OpenTelemetry dependencies that Dependabot did not automatically open. I believe it's safest if we generally just update all of OpenTelemetry to the latest. * sync `api` OpenTelemetry versions to parent versions * Bump go.opentelemetry.io/otel/sdk from 1.16.0 to 1.17.0 (#31185) * AWS OIDC - List EC2: add instance id as label (#31415) When listing EC2 instances we should be able to tell which ones were already added. To do so, we should use the instance-id which is unique. We can't use the Spec.CloudMetadata.AWS.InstanceID because predicate can't use fields that are optional. This PR adds the InstanceID as label. It uses `teleport.dev/instance-id` label key. When creating a Node from WebUI, it will send the same set of labels that was received. So, WebUI will send this same label. When listing EC2 instances, WebUI queries the backend for a list of Nodes of type EC2 EICE and the same `instance-id` and uses the result to show which ones were already added. * update semconv version to match otel --------- Co-authored-by: Marco André Dinis <marco.dinis@goteleport.com> Co-authored-by: Tim Ross <tim.ross@goteleport.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Marco André Dinis <marco.dinis@goteleport.com> Co-authored-by: Tim Ross <tim.ross@goteleport.com> * [v14] Missed OpenTelemetry Updates (#33550) * Bump go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp Bumps [go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp](https://github.com/open-telemetry/opentelemetry-go-contrib) from 0.42.0 to 0.44.0. - [Release notes](https://github.com/open-telemetry/opentelemetry-go-contrib/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/CHANGELOG.md) - [Commits](open-telemetry/opentelemetry-go-contrib@zpages/v0.42.0...zpages/v0.44.0) --- updated-dependencies: - dependency-name: go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * Bump go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp Bumps [go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp](https://github.com/open-telemetry/opentelemetry-go-contrib) from 0.42.0 to 0.44.0. - [Release notes](https://github.com/open-telemetry/opentelemetry-go-contrib/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/CHANGELOG.md) - [Commits](open-telemetry/opentelemetry-go-contrib@zpages/v0.42.0...zpages/v0.44.0) --- updated-dependencies: - dependency-name: go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * Additional OpenTelemetry updates This updates other OpenTelemetry dependencies that Dependabot did not automatically open. I believe it's safest if we generally just update all of OpenTelemetry to the latest. * sync `api` OpenTelemetry versions to parent versions * Bump go.opentelemetry.io/otel/sdk from 1.16.0 to 1.17.0 (#31185) * AWS OIDC - List EC2: add instance id as label (#31415) When listing EC2 instances we should be able to tell which ones were already added. To do so, we should use the instance-id which is unique. We can't use the Spec.CloudMetadata.AWS.InstanceID because predicate can't use fields that are optional. This PR adds the InstanceID as label. It uses `teleport.dev/instance-id` label key. When creating a Node from WebUI, it will send the same set of labels that was received. So, WebUI will send this same label. When listing EC2 instances, WebUI queries the backend for a list of Nodes of type EC2 EICE and the same `instance-id` and uses the result to show which ones were already added. * update semconv version to match otel --------- Co-authored-by: Marco André Dinis <marco.dinis@goteleport.com> Co-authored-by: Tim Ross <tim.ross@goteleport.com> * v14 Examples OpenTelemetry Updates --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Marco André Dinis <marco.dinis@goteleport.com> Co-authored-by: Tim Ross <tim.ross@goteleport.com> * proto update after upgrading grpc * Update Firestore and held-back dependencies (#21190) * update dep * implicit aggregate * fix kind check * remove cring address manip * correct import * invert if * fix rename --------- Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com> * Apply PR feedback * Updated grpc/otelgrpc to 0.44.0 * Removed new `require` block --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Marco André Dinis <marco.dinis@goteleport.com> Co-authored-by: Tim Ross <tim.ross@goteleport.com> Co-authored-by: Joel <jwejdenstal@goteleport.com> Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
This PR takes care of updating the Firestore SDK and related dependencies that were held back by our usage of an old version. This PR remediates the usage of the old batch API which is the reason we held back this dependency.