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

Update Firestore and held-back dependencies #21190

Merged
merged 10 commits into from
Feb 10, 2023
Merged

Update Firestore and held-back dependencies #21190

merged 10 commits into from
Feb 10, 2023

Conversation

xacrimon
Copy link
Contributor

@xacrimon xacrimon commented Feb 2, 2023

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.

@xacrimon xacrimon marked this pull request as ready for review February 6, 2023 16:49
@xacrimon
Copy link
Contributor Author

xacrimon commented Feb 6, 2023

@zmb3 Did you want backports to v12 on this or wait? Memory fails me.

@xacrimon xacrimon added the dependencies Pull requests that update a dependency file label Feb 6, 2023
@xacrimon xacrimon changed the title Update Firestore and related dependencies Update Firestore and held-back dependencies Feb 6, 2023
Copy link
Contributor

@tigrato tigrato left a 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

lib/backend/firestore/firestorebk.go Outdated Show resolved Hide resolved
lib/events/firestoreevents/firestoreevents.go Outdated Show resolved Hide resolved
lib/events/firestoreevents/firestoreevents.go Outdated Show resolved Hide resolved
lib/events/firestoreevents/firestoreevents_test.go Outdated Show resolved Hide resolved
@xacrimon
Copy link
Contributor Author

xacrimon commented Feb 7, 2023

@tigrato thanks! I have now run the manual FS tests using the dev API key, missed these as I closed out early yesterday.

@xacrimon xacrimon requested a review from tigrato February 7, 2023 12:04
Comment on lines 712 to 717
mDocs := make(map[string]*firestore.DocumentSnapshot)
for _, doc := range docs {
mDocs[doc.Ref.Path] = doc
}
Copy link
Contributor

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?

Copy link
Contributor Author

@xacrimon xacrimon Feb 8, 2023

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

Copy link
Contributor

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...)
}

Copy link
Contributor Author

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 Show resolved Hide resolved
lib/backend/firestore/firestorebk.go Outdated Show resolved Hide resolved
Comment on lines 712 to 717
mDocs := make(map[string]*firestore.DocumentSnapshot)
for _, doc := range docs {
mDocs[doc.Ref.Path] = doc
}
Copy link
Contributor

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...)
}

lib/backend/firestore/firestorebk.go Show resolved Hide resolved
lib/backend/firestore/firestorebk.go Show resolved Hide resolved
@xacrimon
Copy link
Contributor Author

xacrimon commented Feb 8, 2023

@tigrato I meant a human/GitHub race condition :)
The comment was about a change that was addressed before the comment was made.

@xacrimon xacrimon requested a review from tigrato February 8, 2023 12:07
@xacrimon xacrimon force-pushed the joel/fs-upd branch 2 times, most recently from 45167c1 to 7a1bcc5 Compare February 8, 2023 12:12
@xacrimon
Copy link
Contributor Author

xacrimon commented Feb 8, 2023

@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?

Copy link
Contributor

@tigrato tigrato left a comment

Choose a reason for hiding this comment

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

LGTM

lib/events/firestoreevents/firestoreevents.go Outdated Show resolved Hide resolved
lib/events/firestoreevents/firestoreevents.go Outdated Show resolved Hide resolved
@xacrimon
Copy link
Contributor Author

xacrimon commented Feb 8, 2023

@rosstimothy Since this is a major API structure switch for how bulk deletes are done, this may need an extra eye during v13 testing.

@xacrimon xacrimon added this pull request to the merge queue Feb 10, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 10, 2023
@rosstimothy rosstimothy added this pull request to the merge queue Feb 10, 2023
Merged via the queue into master with commit f93d401 Feb 10, 2023
Copy link
Contributor

@codingllama codingllama left a 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
Copy link
Contributor

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++ {
Copy link
Contributor

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:

Suggested change
for i := 0; i < len(req.Writes); i++ {
for _ := range req.Writes {

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Even better ☝️

Copy link
Contributor Author

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?

Copy link
Contributor

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(),
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Comment on lines +261 to +267
// 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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

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 could not find an alternative way around this easily.

Copy link
Contributor

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.

@zmb3 zmb3 deleted the joel/fs-upd branch February 24, 2023 22:31
avatus pushed a commit that referenced this pull request Mar 3, 2023
* 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>
@russjones russjones mentioned this pull request Mar 8, 2023
jentfoo pushed a commit that referenced this pull request Oct 16, 2023
* 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>
github-merge-queue bot pushed a commit that referenced this pull request Oct 17, 2023
* [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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file size/sm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants