From 39c53d08e2b7e68158c48121ee9d595889791ea3 Mon Sep 17 00:00:00 2001 From: Jennifer Davis Date: Tue, 3 Sep 2024 12:09:14 -0700 Subject: [PATCH 1/3] chore(automl): remove deprecated samples from automl/language directory (#4355) --- .../entity_extraction/dataset_create.go | 67 ----------------- .../entity_extraction/model_create.go | 63 ---------------- automl/language/entity_extraction/predict.go | 71 ------------------ .../sentiment_analysis/dataset_create.go | 69 ------------------ .../sentiment_analysis/model_create.go | 63 ---------------- automl/language/sentiment_analysis/predict.go | 67 ----------------- .../text_classification/dataset_create.go | 72 ------------------- .../text_classification/model_create.go | 63 ---------------- .../language/text_classification/predict.go | 67 ----------------- 9 files changed, 602 deletions(-) delete mode 100644 automl/language/entity_extraction/dataset_create.go delete mode 100644 automl/language/entity_extraction/model_create.go delete mode 100644 automl/language/entity_extraction/predict.go delete mode 100644 automl/language/sentiment_analysis/dataset_create.go delete mode 100644 automl/language/sentiment_analysis/model_create.go delete mode 100644 automl/language/sentiment_analysis/predict.go delete mode 100644 automl/language/text_classification/dataset_create.go delete mode 100644 automl/language/text_classification/model_create.go delete mode 100644 automl/language/text_classification/predict.go diff --git a/automl/language/entity_extraction/dataset_create.go b/automl/language/entity_extraction/dataset_create.go deleted file mode 100644 index 488751157b..0000000000 --- a/automl/language/entity_extraction/dataset_create.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_language_entity_extraction_create_dataset] -import ( - "context" - "fmt" - "io" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// languageEntityExtractionCreateDataset creates a dataset for text entity extraction. -func languageEntityExtractionCreateDataset(w io.Writer, projectID string, location string, datasetName string) error { - // projectID := "my-project-id" - // location := "us-central1" - // datasetName := "dataset_display_name" - - ctx := context.Background() - client, err := automl.NewClient(ctx) - if err != nil { - return fmt.Errorf("NewClient: %w", err) - } - defer client.Close() - - req := &automlpb.CreateDatasetRequest{ - Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location), - Dataset: &automlpb.Dataset{ - DisplayName: datasetName, - DatasetMetadata: &automlpb.Dataset_TextExtractionDatasetMetadata{ - TextExtractionDatasetMetadata: &automlpb.TextExtractionDatasetMetadata{}, - }, - }, - } - - op, err := client.CreateDataset(ctx, req) - if err != nil { - return fmt.Errorf("CreateDataset: %w", err) - } - fmt.Fprintf(w, "Processing operation name: %q\n", op.Name()) - - dataset, err := op.Wait(ctx) - if err != nil { - return fmt.Errorf("Wait: %w", err) - } - - fmt.Fprintf(w, "Dataset name: %v\n", dataset.GetName()) - - return nil -} - -// [END automl_language_entity_extraction_create_dataset] diff --git a/automl/language/entity_extraction/model_create.go b/automl/language/entity_extraction/model_create.go deleted file mode 100644 index be0f03a869..0000000000 --- a/automl/language/entity_extraction/model_create.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_language_entity_extraction_create_model] -import ( - "context" - "fmt" - "io" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// languageEntityExtractionCreateModel creates a model for text entity extraction. -func languageEntityExtractionCreateModel(w io.Writer, projectID string, location string, datasetID string, modelName string) error { - // projectID := "my-project-id" - // location := "us-central1" - // datasetID := "TEN123456789..." - // modelName := "model_display_name" - - ctx := context.Background() - client, err := automl.NewClient(ctx) - if err != nil { - return fmt.Errorf("NewClient: %w", err) - } - defer client.Close() - - req := &automlpb.CreateModelRequest{ - Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location), - Model: &automlpb.Model{ - DisplayName: modelName, - DatasetId: datasetID, - ModelMetadata: &automlpb.Model_TextExtractionModelMetadata{ - TextExtractionModelMetadata: &automlpb.TextExtractionModelMetadata{}, - }, - }, - } - - op, err := client.CreateModel(ctx, req) - if err != nil { - return fmt.Errorf("CreateModel: %w", err) - } - fmt.Fprintf(w, "Processing operation name: %q\n", op.Name()) - fmt.Fprintf(w, "Training started...\n") - - return nil -} - -// [END automl_language_entity_extraction_create_model] diff --git a/automl/language/entity_extraction/predict.go b/automl/language/entity_extraction/predict.go deleted file mode 100644 index e9a40dd727..0000000000 --- a/automl/language/entity_extraction/predict.go +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_language_entity_extraction_predict] -import ( - "context" - "fmt" - "io" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// languageEntityExtractionPredict does a prediction for text entity extraction. -func languageEntityExtractionPredict(w io.Writer, projectID string, location string, modelID string, content string) error { - // projectID := "my-project-id" - // location := "us-central1" - // modelID := "TEN123456789..." - // content := "text to extract entities" - - ctx := context.Background() - client, err := automl.NewPredictionClient(ctx) - if err != nil { - return fmt.Errorf("NewPredictionClient: %w", err) - } - defer client.Close() - - req := &automlpb.PredictRequest{ - Name: fmt.Sprintf("projects/%s/locations/%s/models/%s", projectID, location, modelID), - Payload: &automlpb.ExamplePayload{ - Payload: &automlpb.ExamplePayload_TextSnippet{ - TextSnippet: &automlpb.TextSnippet{ - Content: content, - MimeType: "text/plain", // Types: "text/plain", "text/html" - }, - }, - }, - } - - resp, err := client.Predict(ctx, req) - if err != nil { - return fmt.Errorf("Predict: %w", err) - } - - for _, payload := range resp.GetPayload() { - fmt.Fprintf(w, "Text extract entity types: %v\n", payload.GetDisplayName()) - fmt.Fprintf(w, "Text score: %v\n", payload.GetTextExtraction().GetScore()) - textSegment := payload.GetTextExtraction().GetTextSegment() - fmt.Fprintf(w, "Text extract entity content: %v\n", textSegment.GetContent()) - fmt.Fprintf(w, "Text start offset: %v\n", textSegment.GetStartOffset()) - fmt.Fprintf(w, "Text end offset: %v\n", textSegment.GetEndOffset()) - } - - return nil -} - -// [END automl_language_entity_extraction_predict] diff --git a/automl/language/sentiment_analysis/dataset_create.go b/automl/language/sentiment_analysis/dataset_create.go deleted file mode 100644 index 6f49701981..0000000000 --- a/automl/language/sentiment_analysis/dataset_create.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_language_sentiment_analysis_create_dataset] -import ( - "context" - "fmt" - "io" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// languageSentimentAnalysisCreateDataset creates a dataset for text sentiment analysis. -func languageSentimentAnalysisCreateDataset(w io.Writer, projectID string, location string, datasetName string) error { - // projectID := "my-project-id" - // location := "us-central1" - // datasetName := "dataset_display_name" - - ctx := context.Background() - client, err := automl.NewClient(ctx) - if err != nil { - return fmt.Errorf("NewClient: %w", err) - } - defer client.Close() - - req := &automlpb.CreateDatasetRequest{ - Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location), - Dataset: &automlpb.Dataset{ - DisplayName: datasetName, - DatasetMetadata: &automlpb.Dataset_TextSentimentDatasetMetadata{ - TextSentimentDatasetMetadata: &automlpb.TextSentimentDatasetMetadata{ - SentimentMax: 4, // Possible max sentiment score: 1-10 - }, - }, - }, - } - - op, err := client.CreateDataset(ctx, req) - if err != nil { - return fmt.Errorf("CreateDataset: %w", err) - } - fmt.Fprintf(w, "Processing operation name: %q\n", op.Name()) - - dataset, err := op.Wait(ctx) - if err != nil { - return fmt.Errorf("Wait: %w", err) - } - - fmt.Fprintf(w, "Dataset name: %v\n", dataset.GetName()) - - return nil -} - -// [END automl_language_sentiment_analysis_create_dataset] diff --git a/automl/language/sentiment_analysis/model_create.go b/automl/language/sentiment_analysis/model_create.go deleted file mode 100644 index 26598fcd49..0000000000 --- a/automl/language/sentiment_analysis/model_create.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_language_sentiment_analysis_create_model] -import ( - "context" - "fmt" - "io" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// languageSentimentAnalysisCreateModel creates a model for text sentiment analysis. -func languageSentimentAnalysisCreateModel(w io.Writer, projectID string, location string, datasetID string, modelName string) error { - // projectID := "my-project-id" - // location := "us-central1" - // datasetID := "TST123456789..." - // modelName := "model_display_name" - - ctx := context.Background() - client, err := automl.NewClient(ctx) - if err != nil { - return fmt.Errorf("NewClient: %w", err) - } - defer client.Close() - - req := &automlpb.CreateModelRequest{ - Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location), - Model: &automlpb.Model{ - DisplayName: modelName, - DatasetId: datasetID, - ModelMetadata: &automlpb.Model_TextSentimentModelMetadata{ - TextSentimentModelMetadata: &automlpb.TextSentimentModelMetadata{}, - }, - }, - } - - op, err := client.CreateModel(ctx, req) - if err != nil { - return fmt.Errorf("CreateModel: %w", err) - } - fmt.Fprintf(w, "Processing operation name: %q\n", op.Name()) - fmt.Fprintf(w, "Training started...\n") - - return nil -} - -// [END automl_language_sentiment_analysis_create_model] diff --git a/automl/language/sentiment_analysis/predict.go b/automl/language/sentiment_analysis/predict.go deleted file mode 100644 index e89c2f88fa..0000000000 --- a/automl/language/sentiment_analysis/predict.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_language_sentiment_analysis_predict] -import ( - "context" - "fmt" - "io" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// languageSentimentAnalysisPredict does a prediction for text sentiment analysis. -func languageSentimentAnalysisPredict(w io.Writer, projectID string, location string, modelID string, content string) error { - // projectID := "my-project-id" - // location := "us-central1" - // modelID := "TST123456789..." - // content := "text to analyze sentiment" - - ctx := context.Background() - client, err := automl.NewPredictionClient(ctx) - if err != nil { - return fmt.Errorf("NewPredictionClient: %w", err) - } - defer client.Close() - - req := &automlpb.PredictRequest{ - Name: fmt.Sprintf("projects/%s/locations/%s/models/%s", projectID, location, modelID), - Payload: &automlpb.ExamplePayload{ - Payload: &automlpb.ExamplePayload_TextSnippet{ - TextSnippet: &automlpb.TextSnippet{ - Content: content, - MimeType: "text/plain", // Types: "text/plain", "text/html" - }, - }, - }, - } - - resp, err := client.Predict(ctx, req) - if err != nil { - return fmt.Errorf("Predict: %w", err) - } - - for _, payload := range resp.GetPayload() { - fmt.Fprintf(w, "Predicted class name: %v\n", payload.GetDisplayName()) - fmt.Fprintf(w, "Predicted sentiment score: %v\n", payload.GetTextSentiment().GetSentiment()) - } - - return nil -} - -// [END automl_language_sentiment_analysis_predict] diff --git a/automl/language/text_classification/dataset_create.go b/automl/language/text_classification/dataset_create.go deleted file mode 100644 index db2ca6df36..0000000000 --- a/automl/language/text_classification/dataset_create.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_language_text_classification_create_dataset] -import ( - "context" - "fmt" - "io" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// languageTextClassificationCreateDataset creates a dataset for text classification. -func languageTextClassificationCreateDataset(w io.Writer, projectID string, location string, datasetName string) error { - // projectID := "my-project-id" - // location := "us-central1" - // datasetName := "dataset_display_name" - - ctx := context.Background() - client, err := automl.NewClient(ctx) - if err != nil { - return fmt.Errorf("NewClient: %w", err) - } - defer client.Close() - - req := &automlpb.CreateDatasetRequest{ - Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location), - Dataset: &automlpb.Dataset{ - DisplayName: datasetName, - DatasetMetadata: &automlpb.Dataset_TextClassificationDatasetMetadata{ - TextClassificationDatasetMetadata: &automlpb.TextClassificationDatasetMetadata{ - // Specify the classification type: - // - MULTILABEL: Multiple labels are allowed for one example. - // - MULTICLASS: At most one label is allowed per example. - ClassificationType: automlpb.ClassificationType_MULTICLASS, - }, - }, - }, - } - - op, err := client.CreateDataset(ctx, req) - if err != nil { - return fmt.Errorf("CreateDataset: %w", err) - } - fmt.Fprintf(w, "Processing operation name: %q\n", op.Name()) - - dataset, err := op.Wait(ctx) - if err != nil { - return fmt.Errorf("Wait: %w", err) - } - - fmt.Fprintf(w, "Dataset name: %v\n", dataset.GetName()) - - return nil -} - -// [END automl_language_text_classification_create_dataset] diff --git a/automl/language/text_classification/model_create.go b/automl/language/text_classification/model_create.go deleted file mode 100644 index 3ab8103789..0000000000 --- a/automl/language/text_classification/model_create.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_language_text_classification_create_model] -import ( - "context" - "fmt" - "io" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// languageTextClassificationCreateModel creates a model for text classification. -func languageTextClassificationCreateModel(w io.Writer, projectID string, location string, datasetID string, modelName string) error { - // projectID := "my-project-id" - // location := "us-central1" - // datasetID := "TCN123456789..." - // modelName := "model_display_name" - - ctx := context.Background() - client, err := automl.NewClient(ctx) - if err != nil { - return fmt.Errorf("NewClient: %w", err) - } - defer client.Close() - - req := &automlpb.CreateModelRequest{ - Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location), - Model: &automlpb.Model{ - DisplayName: modelName, - DatasetId: datasetID, - ModelMetadata: &automlpb.Model_TextClassificationModelMetadata{ - TextClassificationModelMetadata: &automlpb.TextClassificationModelMetadata{}, - }, - }, - } - - op, err := client.CreateModel(ctx, req) - if err != nil { - return fmt.Errorf("CreateModel: %w", err) - } - fmt.Fprintf(w, "Processing operation name: %q\n", op.Name()) - fmt.Fprintf(w, "Training started...\n") - - return nil -} - -// [END automl_language_text_classification_create_model] diff --git a/automl/language/text_classification/predict.go b/automl/language/text_classification/predict.go deleted file mode 100644 index c7438fde34..0000000000 --- a/automl/language/text_classification/predict.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_language_text_classification_predict] -import ( - "context" - "fmt" - "io" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// languageTextClassificationPredict does a prediction for text classification. -func languageTextClassificationPredict(w io.Writer, projectID string, location string, modelID string, content string) error { - // projectID := "my-project-id" - // location := "us-central1" - // modelID := "TCN123456789..." - // content := "text to classify" - - ctx := context.Background() - client, err := automl.NewPredictionClient(ctx) - if err != nil { - return fmt.Errorf("NewPredictionClient: %w", err) - } - defer client.Close() - - req := &automlpb.PredictRequest{ - Name: fmt.Sprintf("projects/%s/locations/%s/models/%s", projectID, location, modelID), - Payload: &automlpb.ExamplePayload{ - Payload: &automlpb.ExamplePayload_TextSnippet{ - TextSnippet: &automlpb.TextSnippet{ - Content: content, - MimeType: "text/plain", // Types: "text/plain", "text/html" - }, - }, - }, - } - - resp, err := client.Predict(ctx, req) - if err != nil { - return fmt.Errorf("Predict: %w", err) - } - - for _, payload := range resp.GetPayload() { - fmt.Fprintf(w, "Predicted class name: %v\n", payload.GetDisplayName()) - fmt.Fprintf(w, "Predicted class score: %v\n", payload.GetClassification().GetScore()) - } - - return nil -} - -// [END automl_language_text_classification_predict] From e0bf956c36b91258e8411740d36d1b6852add6ef Mon Sep 17 00:00:00 2001 From: Jennifer Davis Date: Tue, 3 Sep 2024 12:24:28 -0700 Subject: [PATCH 2/3] chore(automl): remove automl vision samples (#4356) Co-authored-by: Drew Brown --- .../vision/classification/dataset_create.go | 72 --------------- automl/vision/classification/model_create.go | 65 -------------- .../model_deploy_with_node_count.go | 65 -------------- automl/vision/classification/predict.go | 85 ------------------ .../vision/object_detection/dataset_create.go | 67 -------------- .../vision/object_detection/model_create.go | 63 ------------- .../model_deploy_with_node_count.go | 65 -------------- automl/vision/object_detection/predict.go | 90 ------------------- 8 files changed, 572 deletions(-) delete mode 100644 automl/vision/classification/dataset_create.go delete mode 100644 automl/vision/classification/model_create.go delete mode 100644 automl/vision/classification/model_deploy_with_node_count.go delete mode 100644 automl/vision/classification/predict.go delete mode 100644 automl/vision/object_detection/dataset_create.go delete mode 100644 automl/vision/object_detection/model_create.go delete mode 100644 automl/vision/object_detection/model_deploy_with_node_count.go delete mode 100644 automl/vision/object_detection/predict.go diff --git a/automl/vision/classification/dataset_create.go b/automl/vision/classification/dataset_create.go deleted file mode 100644 index 9b147acefc..0000000000 --- a/automl/vision/classification/dataset_create.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_vision_classification_create_dataset] -import ( - "context" - "fmt" - "io" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// visionClassificationCreateDataset creates a dataset for image classification. -func visionClassificationCreateDataset(w io.Writer, projectID string, location string, datasetName string) error { - // projectID := "my-project-id" - // location := "us-central1" - // datasetName := "dataset_display_name" - - ctx := context.Background() - client, err := automl.NewClient(ctx) - if err != nil { - return fmt.Errorf("NewClient: %w", err) - } - defer client.Close() - - req := &automlpb.CreateDatasetRequest{ - Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location), - Dataset: &automlpb.Dataset{ - DisplayName: datasetName, - DatasetMetadata: &automlpb.Dataset_ImageClassificationDatasetMetadata{ - ImageClassificationDatasetMetadata: &automlpb.ImageClassificationDatasetMetadata{ - // Specify the classification type: - // - MULTILABEL: Multiple labels are allowed for one example. - // - MULTICLASS: At most one label is allowed per example. - ClassificationType: automlpb.ClassificationType_MULTILABEL, - }, - }, - }, - } - - op, err := client.CreateDataset(ctx, req) - if err != nil { - return fmt.Errorf("CreateDataset: %w", err) - } - fmt.Fprintf(w, "Processing operation name: %q\n", op.Name()) - - dataset, err := op.Wait(ctx) - if err != nil { - return fmt.Errorf("Wait: %w", err) - } - - fmt.Fprintf(w, "Dataset name: %v\n", dataset.GetName()) - - return nil -} - -// [END automl_vision_classification_create_dataset] diff --git a/automl/vision/classification/model_create.go b/automl/vision/classification/model_create.go deleted file mode 100644 index df4ccd19b6..0000000000 --- a/automl/vision/classification/model_create.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_vision_classification_create_model] -import ( - "context" - "fmt" - "io" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// visionClassificationCreateModel creates a model for image classification. -func visionClassificationCreateModel(w io.Writer, projectID string, location string, datasetID string, modelName string) error { - // projectID := "my-project-id" - // location := "us-central1" - // datasetID := "ICN123456789..." - // modelName := "model_display_name" - - ctx := context.Background() - client, err := automl.NewClient(ctx) - if err != nil { - return fmt.Errorf("NewClient: %w", err) - } - defer client.Close() - - req := &automlpb.CreateModelRequest{ - Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location), - Model: &automlpb.Model{ - DisplayName: modelName, - DatasetId: datasetID, - ModelMetadata: &automlpb.Model_ImageClassificationModelMetadata{ - ImageClassificationModelMetadata: &automlpb.ImageClassificationModelMetadata{ - TrainBudgetMilliNodeHours: 1000, // 1000 milli-node hours are 1 hour - }, - }, - }, - } - - op, err := client.CreateModel(ctx, req) - if err != nil { - return fmt.Errorf("CreateModel: %w", err) - } - fmt.Fprintf(w, "Processing operation name: %q\n", op.Name()) - fmt.Fprintf(w, "Training started...\n") - - return nil -} - -// [END automl_vision_classification_create_model] diff --git a/automl/vision/classification/model_deploy_with_node_count.go b/automl/vision/classification/model_deploy_with_node_count.go deleted file mode 100644 index 0c1a9da179..0000000000 --- a/automl/vision/classification/model_deploy_with_node_count.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_vision_classification_deploy_model_node_count] -import ( - "context" - "fmt" - "io" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// visionClassificationDeployModelWithNodeCount deploys a model with node count. -func visionClassificationDeployModelWithNodeCount(w io.Writer, projectID string, location string, modelID string) error { - // projectID := "my-project-id" - // location := "us-central1" - // modelID := "ICN123456789..." - - ctx := context.Background() - client, err := automl.NewClient(ctx) - if err != nil { - return fmt.Errorf("NewClient: %w", err) - } - defer client.Close() - - req := &automlpb.DeployModelRequest{ - Name: fmt.Sprintf("projects/%s/locations/%s/models/%s", projectID, location, modelID), - ModelDeploymentMetadata: &automlpb.DeployModelRequest_ImageClassificationModelDeploymentMetadata{ - ImageClassificationModelDeploymentMetadata: &automlpb.ImageClassificationModelDeploymentMetadata{ - NodeCount: 2, - }, - }, - } - - op, err := client.DeployModel(ctx, req) - if err != nil { - return fmt.Errorf("DeployModel: %w", err) - } - fmt.Fprintf(w, "Processing operation name: %q\n", op.Name()) - - if err := op.Wait(ctx); err != nil { - return fmt.Errorf("Wait: %w", err) - } - - fmt.Fprintf(w, "Model deployed.\n") - - return nil -} - -// [END automl_vision_classification_deploy_model_node_count] diff --git a/automl/vision/classification/predict.go b/automl/vision/classification/predict.go deleted file mode 100644 index a4a61db62d..0000000000 --- a/automl/vision/classification/predict.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_vision_classification_predict] -import ( - "context" - "fmt" - "io" - "io/ioutil" - "os" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// visionClassificationPredict does a prediction for image classification. -func visionClassificationPredict(w io.Writer, projectID string, location string, modelID string, filePath string) error { - // projectID := "my-project-id" - // location := "us-central1" - // modelID := "ICN123456789..." - // filePath := "path/to/image.jpg" - - ctx := context.Background() - client, err := automl.NewPredictionClient(ctx) - if err != nil { - return fmt.Errorf("NewPredictionClient: %w", err) - } - defer client.Close() - - file, err := os.Open(filePath) - if err != nil { - return fmt.Errorf("Open: %w", err) - } - defer file.Close() - bytes, err := ioutil.ReadAll(file) - if err != nil { - return fmt.Errorf("ReadAll: %w", err) - } - - req := &automlpb.PredictRequest{ - Name: fmt.Sprintf("projects/%s/locations/%s/models/%s", projectID, location, modelID), - Payload: &automlpb.ExamplePayload{ - Payload: &automlpb.ExamplePayload_Image{ - Image: &automlpb.Image{ - Data: &automlpb.Image_ImageBytes{ - ImageBytes: bytes, - }, - }, - }, - }, - // Params is additional domain-specific parameters. - Params: map[string]string{ - // score_threshold is used to filter the result. - "score_threshold": "0.8", - }, - } - - resp, err := client.Predict(ctx, req) - if err != nil { - return fmt.Errorf("Predict: %w", err) - } - - for _, payload := range resp.GetPayload() { - fmt.Fprintf(w, "Predicted class name: %v\n", payload.GetDisplayName()) - fmt.Fprintf(w, "Predicted class score: %v\n", payload.GetClassification().GetScore()) - } - - return nil -} - -// [END automl_vision_classification_predict] diff --git a/automl/vision/object_detection/dataset_create.go b/automl/vision/object_detection/dataset_create.go deleted file mode 100644 index a5fcd055f6..0000000000 --- a/automl/vision/object_detection/dataset_create.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_vision_object_detection_create_dataset] -import ( - "context" - "fmt" - "io" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// visionObjectDetectionCreateDataset creates a dataset for image object detection. -func visionObjectDetectionCreateDataset(w io.Writer, projectID string, location string, datasetName string) error { - // projectID := "my-project-id" - // location := "us-central1" - // datasetName := "dataset_display_name" - - ctx := context.Background() - client, err := automl.NewClient(ctx) - if err != nil { - return fmt.Errorf("NewClient: %w", err) - } - defer client.Close() - - req := &automlpb.CreateDatasetRequest{ - Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location), - Dataset: &automlpb.Dataset{ - DisplayName: datasetName, - DatasetMetadata: &automlpb.Dataset_ImageObjectDetectionDatasetMetadata{ - ImageObjectDetectionDatasetMetadata: &automlpb.ImageObjectDetectionDatasetMetadata{}, - }, - }, - } - - op, err := client.CreateDataset(ctx, req) - if err != nil { - return fmt.Errorf("CreateDataset: %w", err) - } - fmt.Fprintf(w, "Processing operation name: %q\n", op.Name()) - - dataset, err := op.Wait(ctx) - if err != nil { - return fmt.Errorf("Wait: %w", err) - } - - fmt.Fprintf(w, "Dataset name: %v\n", dataset.GetName()) - - return nil -} - -// [END automl_vision_object_detection_create_dataset] diff --git a/automl/vision/object_detection/model_create.go b/automl/vision/object_detection/model_create.go deleted file mode 100644 index 76d6d2e399..0000000000 --- a/automl/vision/object_detection/model_create.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_vision_object_detection_create_model] -import ( - "context" - "fmt" - "io" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// visionObjectDetectionCreateModel creates a model for image object detection. -func visionObjectDetectionCreateModel(w io.Writer, projectID string, location string, datasetID string, modelName string) error { - // projectID := "my-project-id" - // location := "us-central1" - // datasetID := "IOD123456789..." - // modelName := "model_display_name" - - ctx := context.Background() - client, err := automl.NewClient(ctx) - if err != nil { - return fmt.Errorf("NewClient: %w", err) - } - defer client.Close() - - req := &automlpb.CreateModelRequest{ - Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location), - Model: &automlpb.Model{ - DisplayName: modelName, - DatasetId: datasetID, - ModelMetadata: &automlpb.Model_ImageObjectDetectionModelMetadata{ - ImageObjectDetectionModelMetadata: &automlpb.ImageObjectDetectionModelMetadata{}, - }, - }, - } - - op, err := client.CreateModel(ctx, req) - if err != nil { - return fmt.Errorf("CreateModel: %w", err) - } - fmt.Fprintf(w, "Processing operation name: %q\n", op.Name()) - fmt.Fprintf(w, "Training started...\n") - - return nil -} - -// [END automl_vision_object_detection_create_model] diff --git a/automl/vision/object_detection/model_deploy_with_node_count.go b/automl/vision/object_detection/model_deploy_with_node_count.go deleted file mode 100644 index 0a87ec8bee..0000000000 --- a/automl/vision/object_detection/model_deploy_with_node_count.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_vision_object_detection_deploy_model_node_count] -import ( - "context" - "fmt" - "io" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// visionObjectDetectionDeployModelWithNodeCount deploys a model with node count. -func visionObjectDetectionDeployModelWithNodeCount(w io.Writer, projectID string, location string, modelID string) error { - // projectID := "my-project-id" - // location := "us-central1" - // modelID := "IOD123456789..." - - ctx := context.Background() - client, err := automl.NewClient(ctx) - if err != nil { - return fmt.Errorf("NewClient: %w", err) - } - defer client.Close() - - req := &automlpb.DeployModelRequest{ - Name: fmt.Sprintf("projects/%s/locations/%s/models/%s", projectID, location, modelID), - ModelDeploymentMetadata: &automlpb.DeployModelRequest_ImageObjectDetectionModelDeploymentMetadata{ - ImageObjectDetectionModelDeploymentMetadata: &automlpb.ImageObjectDetectionModelDeploymentMetadata{ - NodeCount: 2, - }, - }, - } - - op, err := client.DeployModel(ctx, req) - if err != nil { - return fmt.Errorf("DeployModel: %w", err) - } - fmt.Fprintf(w, "Processing operation name: %q\n", op.Name()) - - if err := op.Wait(ctx); err != nil { - return fmt.Errorf("Wait: %w", err) - } - - fmt.Fprintf(w, "Model deployed.\n") - - return nil -} - -// [END automl_vision_object_detection_deploy_model_node_count] diff --git a/automl/vision/object_detection/predict.go b/automl/vision/object_detection/predict.go deleted file mode 100644 index fca888355a..0000000000 --- a/automl/vision/object_detection/predict.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package automl contains samples for Google Cloud AutoML API v1. -package automl - -// [START automl_vision_object_detection_predict] -import ( - "context" - "fmt" - "io" - "io/ioutil" - "os" - - automl "cloud.google.com/go/automl/apiv1" - "cloud.google.com/go/automl/apiv1/automlpb" -) - -// visionObjectDetectionPredict does a prediction for image classification. -func visionObjectDetectionPredict(w io.Writer, projectID string, location string, modelID string, filePath string) error { - // projectID := "my-project-id" - // location := "us-central1" - // modelID := "IOD123456789..." - // filePath := "path/to/image.jpg" - - ctx := context.Background() - client, err := automl.NewPredictionClient(ctx) - if err != nil { - return fmt.Errorf("NewPredictionClient: %w", err) - } - defer client.Close() - - file, err := os.Open(filePath) - if err != nil { - return fmt.Errorf("Open: %w", err) - } - defer file.Close() - bytes, err := ioutil.ReadAll(file) - if err != nil { - return fmt.Errorf("ReadAll: %w", err) - } - - req := &automlpb.PredictRequest{ - Name: fmt.Sprintf("projects/%s/locations/%s/models/%s", projectID, location, modelID), - Payload: &automlpb.ExamplePayload{ - Payload: &automlpb.ExamplePayload_Image{ - Image: &automlpb.Image{ - Data: &automlpb.Image_ImageBytes{ - ImageBytes: bytes, - }, - }, - }, - }, - // Params is additional domain-specific parameters. - Params: map[string]string{ - // score_threshold is used to filter the result. - "score_threshold": "0.8", - }, - } - - resp, err := client.Predict(ctx, req) - if err != nil { - return fmt.Errorf("Predict: %w", err) - } - - for _, payload := range resp.GetPayload() { - fmt.Fprintf(w, "Predicted class name: %v\n", payload.GetDisplayName()) - fmt.Fprintf(w, "Predicted class score: %v\n", payload.GetImageObjectDetection().GetScore()) - boundingBox := payload.GetImageObjectDetection().GetBoundingBox() - fmt.Fprintf(w, "Normalized vertices:\n") - for _, vertex := range boundingBox.GetNormalizedVertices() { - fmt.Fprintf(w, "\tX: %v, Y: %v\n", vertex.GetX(), vertex.GetY()) - } - } - - return nil -} - -// [END automl_vision_object_detection_predict] From 86a93166723803996f796f4873d31a9b6c4dc12a Mon Sep 17 00:00:00 2001 From: Alex Hong <9397363+hongalex@users.noreply.github.com> Date: Wed, 4 Sep 2024 10:09:17 -0700 Subject: [PATCH 3/3] feat(pubsub): add otel tracing samples (#3961) * feat(pubsub): add otel tracing samples * fix pull sample location * add pull subscription sample * run go mod tidy * add publish and subscribe tests * use trace client to check traces in tests * run go mod tidy --------- Co-authored-by: Eric Schmidt Co-authored-by: Jennifer Davis --- pubsub/go.mod | 51 ++++----- pubsub/go.sum | 124 ++++++++++++---------- pubsub/subscriptions/pull_otel_tracing.go | 98 +++++++++++++++++ pubsub/subscriptions/subscription_test.go | 70 ++++++++++++ pubsub/topics/publish_otel_tracing.go | 87 +++++++++++++++ pubsub/topics/topics_test.go | 58 ++++++++++ 6 files changed, 408 insertions(+), 80 deletions(-) create mode 100644 pubsub/subscriptions/pull_otel_tracing.go create mode 100644 pubsub/topics/publish_otel_tracing.go diff --git a/pubsub/go.mod b/pubsub/go.mod index 28b5510788..3a129a26ba 100644 --- a/pubsub/go.mod +++ b/pubsub/go.mod @@ -4,24 +4,29 @@ go 1.21 require ( cloud.google.com/go/bigquery v1.62.0 - cloud.google.com/go/iam v1.1.11 - cloud.google.com/go/pubsub v1.40.0 + cloud.google.com/go/iam v1.2.0 + cloud.google.com/go/pubsub v1.42.0 cloud.google.com/go/storage v1.43.0 - github.com/GoogleCloudPlatform/golang-samples v0.0.0-20240724083556-7f760db013b7 + cloud.google.com/go/trace v1.11.0 + github.com/GoogleCloudPlatform/golang-samples v0.0.0-20240820230436-761d0ae7aeff + github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.24.1 github.com/google/go-cmp v0.6.0 github.com/google/uuid v1.6.0 github.com/googleapis/gax-go/v2 v2.13.0 github.com/linkedin/goavro/v2 v2.13.0 - google.golang.org/api v0.189.0 + go.opentelemetry.io/otel v1.28.0 + go.opentelemetry.io/otel/sdk v1.28.0 + google.golang.org/api v0.193.0 google.golang.org/grpc v1.65.0 google.golang.org/protobuf v1.34.2 ) require ( - cloud.google.com/go v0.115.0 // indirect - cloud.google.com/go/auth v0.7.2 // indirect - cloud.google.com/go/auth/oauth2adapt v0.2.3 // indirect + cloud.google.com/go v0.115.1 // indirect + cloud.google.com/go/auth v0.9.0 // indirect + cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect cloud.google.com/go/compute/metadata v0.5.0 // indirect + github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.48.1 // indirect github.com/apache/arrow/go/v15 v15.0.2 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-logr/logr v1.4.2 // indirect @@ -31,7 +36,7 @@ require ( github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/flatbuffers v23.5.26+incompatible // indirect - github.com/google/s2a-go v0.1.7 // indirect + github.com/google/s2a-go v0.1.8 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect github.com/klauspost/compress v1.16.7 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect @@ -39,24 +44,22 @@ require ( github.com/zeebo/xxh3 v1.0.2 // indirect go.einride.tech/aip v0.67.1 // indirect go.opencensus.io v0.24.0 // indirect - go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect - go.opentelemetry.io/otel v1.24.0 // indirect - go.opentelemetry.io/otel/metric v1.24.0 // indirect - go.opentelemetry.io/otel/sdk v1.24.0 // indirect - go.opentelemetry.io/otel/trace v1.24.0 // indirect - golang.org/x/crypto v0.25.0 // indirect + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect + go.opentelemetry.io/otel/metric v1.28.0 // indirect + go.opentelemetry.io/otel/trace v1.28.0 // indirect + golang.org/x/crypto v0.26.0 // indirect golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect golang.org/x/mod v0.18.0 // indirect - golang.org/x/net v0.27.0 // indirect - golang.org/x/oauth2 v0.21.0 // indirect - golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.22.0 // indirect - golang.org/x/text v0.16.0 // indirect - golang.org/x/time v0.5.0 // indirect + golang.org/x/net v0.28.0 // indirect + golang.org/x/oauth2 v0.22.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.24.0 // indirect + golang.org/x/text v0.17.0 // indirect + golang.org/x/time v0.6.0 // indirect golang.org/x/tools v0.22.0 // indirect golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect - google.golang.org/genproto v0.0.0-20240722135656-d784300faade // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240722135656-d784300faade // indirect + google.golang.org/genproto v0.0.0-20240820151423-278611b39280 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240820151423-278611b39280 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240820151423-278611b39280 // indirect ) diff --git a/pubsub/go.sum b/pubsub/go.sum index e069c7ed9d..05d82df638 100644 --- a/pubsub/go.sum +++ b/pubsub/go.sum @@ -1,29 +1,41 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.115.0 h1:CnFSK6Xo3lDYRoBKEcAtia6VSC837/ZkJuRduSFnr14= -cloud.google.com/go v0.115.0/go.mod h1:8jIM5vVgoAEoiVxQ/O4BFTfHqulPZgs/ufEzMcFMdWU= -cloud.google.com/go/auth v0.7.2 h1:uiha352VrCDMXg+yoBtaD0tUF4Kv9vrtrWPYXwutnDE= -cloud.google.com/go/auth v0.7.2/go.mod h1:VEc4p5NNxycWQTMQEDQF0bd6aTMb6VgYDXEwiJJQAbs= -cloud.google.com/go/auth/oauth2adapt v0.2.3 h1:MlxF+Pd3OmSudg/b1yZ5lJwoXCEaeedAguodky1PcKI= -cloud.google.com/go/auth/oauth2adapt v0.2.3/go.mod h1:tMQXOfZzFuNuUxOypHlQEXgdfX5cuhwU+ffUuXRJE8I= +cloud.google.com/go v0.115.1 h1:Jo0SM9cQnSkYfp44+v+NQXHpcHqlnRJk2qxh6yvxxxQ= +cloud.google.com/go v0.115.1/go.mod h1:DuujITeaufu3gL68/lOFIirVNJwQeyf5UXyi+Wbgknc= +cloud.google.com/go/auth v0.9.0 h1:cYhKl1JUhynmxjXfrk4qdPc6Amw7i+GC9VLflgT0p5M= +cloud.google.com/go/auth v0.9.0/go.mod h1:2HsApZBr9zGZhC9QAXsYVYaWk8kNUt37uny+XVKi7wM= +cloud.google.com/go/auth/oauth2adapt v0.2.4 h1:0GWE/FUsXhf6C+jAkWgYm7X9tK8cuEIfy19DBn6B6bY= +cloud.google.com/go/auth/oauth2adapt v0.2.4/go.mod h1:jC/jOpwFP6JBxhB3P5Rr0a9HLMC/Pe3eaL4NmdvqPtc= cloud.google.com/go/bigquery v1.62.0 h1:SYEA2f7fKqbSRRBHb7g0iHTtZvtPSPYdXfmqsjpsBwo= cloud.google.com/go/bigquery v1.62.0/go.mod h1:5ee+ZkF1x/ntgCsFQJAQTM3QkAZOecfCmvxhkJsWRSA= cloud.google.com/go/compute/metadata v0.5.0 h1:Zr0eK8JbFv6+Wi4ilXAR8FJ3wyNdpxHKJNPos6LTZOY= cloud.google.com/go/compute/metadata v0.5.0/go.mod h1:aHnloV2TPI38yx4s9+wAZhHykWvVCfu7hQbF+9CWoiY= -cloud.google.com/go/datacatalog v1.20.3 h1:lzMtWaUlaz9Bd9anvq2KBZwcFujzhVuxhIz1MsqRJv8= -cloud.google.com/go/datacatalog v1.20.3/go.mod h1:AKC6vAy5urnMg5eJK3oUjy8oa5zMbiY33h125l8lmlo= -cloud.google.com/go/iam v1.1.11 h1:0mQ8UKSfdHLut6pH9FM3bI55KWR46ketn0PuXleDyxw= -cloud.google.com/go/iam v1.1.11/go.mod h1:biXoiLWYIKntto2joP+62sd9uW5EpkZmKIvfNcTWlnQ= -cloud.google.com/go/kms v1.18.2 h1:EGgD0B9k9tOOkbPhYW1PHo2W0teamAUYMOUIcDRMfPk= -cloud.google.com/go/kms v1.18.2/go.mod h1:YFz1LYrnGsXARuRePL729oINmN5J/5e7nYijgvfiIeY= -cloud.google.com/go/longrunning v0.5.9 h1:haH9pAuXdPAMqHvzX0zlWQigXT7B0+CL4/2nXXdBo5k= -cloud.google.com/go/longrunning v0.5.9/go.mod h1:HD+0l9/OOW0za6UWdKJtXoFAX/BGg/3Wj8p10NeWF7c= -cloud.google.com/go/pubsub v1.40.0 h1:0LdP+zj5XaPAGtWr2V6r88VXJlmtaB/+fde1q3TU8M0= -cloud.google.com/go/pubsub v1.40.0/go.mod h1:BVJI4sI2FyXp36KFKvFwcfDRDfR8MiLT8mMhmIhdAeA= +cloud.google.com/go/datacatalog v1.21.1 h1:l8yPkaMTlIX/437kBKGURvk4dtZIbotHBuSX2nLbJY8= +cloud.google.com/go/datacatalog v1.21.1/go.mod h1:23qsWWm592aQHwZ4or7VDjNhx7DeNklHAPE3GM47d1U= +cloud.google.com/go/iam v1.2.0 h1:kZKMKVNk/IsSSc/udOb83K0hL/Yh/Gcqpz+oAkoIFN8= +cloud.google.com/go/iam v1.2.0/go.mod h1:zITGuWgsLZxd8OwAlX+eMFgZDXzBm7icj1PVTYG766Q= +cloud.google.com/go/kms v1.18.5 h1:75LSlVs60hyHK3ubs2OHd4sE63OAMcM2BdSJc2bkuM4= +cloud.google.com/go/kms v1.18.5/go.mod h1:yXunGUGzabH8rjUPImp2ndHiGolHeWJJ0LODLedicIY= +cloud.google.com/go/logging v1.11.0 h1:v3ktVzXMV7CwHq1MBF65wcqLMA7i+z3YxbUsoK7mOKs= +cloud.google.com/go/logging v1.11.0/go.mod h1:5LDiJC/RxTt+fHc1LAt20R9TKiUTReDg6RuuFOZ67+A= +cloud.google.com/go/longrunning v0.5.12 h1:5LqSIdERr71CqfUsFlJdBpOkBH8FBCFD7P1nTWy3TYE= +cloud.google.com/go/longrunning v0.5.12/go.mod h1:S5hMV8CDJ6r50t2ubVJSKQVv5u0rmik5//KgLO3k4lU= +cloud.google.com/go/monitoring v1.20.4 h1:zwcViK7mT9SV0kzKqLOI3spRadvsmvw/R9z1MHNeC0E= +cloud.google.com/go/monitoring v1.20.4/go.mod h1:v7F/UcLRw15EX7xq565N7Ae5tnYEE28+Cl717aTXG4c= +cloud.google.com/go/pubsub v1.42.0 h1:PVTbzorLryFL5ue8esTS2BfehUs0ahyNOY9qcd+HMOs= +cloud.google.com/go/pubsub v1.42.0/go.mod h1:KADJ6s4MbTwhXmse/50SebEhE4SmUwHi48z3/dHar1Y= cloud.google.com/go/storage v1.43.0 h1:CcxnSohZwizt4LCzQHWvBf1/kvtHUn7gk9QERXPyXFs= cloud.google.com/go/storage v1.43.0/go.mod h1:ajvxEa7WmZS1PxvKRq4bq0tFT3vMd502JwstCcYv0Q0= +cloud.google.com/go/trace v1.11.0 h1:UHX6cOJm45Zw/KIbqHe4kII8PupLt/V5tscZUkeiJVI= +cloud.google.com/go/trace v1.11.0/go.mod h1:Aiemdi52635dBR7o3zuc9lLjXo3BwGaChEjCa3tJNmM= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/GoogleCloudPlatform/golang-samples v0.0.0-20240724083556-7f760db013b7 h1:yGCaiv5IE3WoRTUOXHD/jybC2RIGTdCKuNwwmwQq7u4= -github.com/GoogleCloudPlatform/golang-samples v0.0.0-20240724083556-7f760db013b7/go.mod h1:CK/v6fB0p6JTQtDAQ1UyKABPBiHRsA3+qbX2yuZZk1w= +github.com/GoogleCloudPlatform/golang-samples v0.0.0-20240820230436-761d0ae7aeff h1:eoQLT2CbHlA5oNrfUnVbRjM2aXp9lHBNhdnCe9oDKj4= +github.com/GoogleCloudPlatform/golang-samples v0.0.0-20240820230436-761d0ae7aeff/go.mod h1:zNbBG/YoLJKDB1iQueDUxex/8bI9YqLK3BTh2kMtejI= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.24.1 h1:01bHLeqkrxYSkjvyTBEZ8rxBxDhWm1snWGEW73Te4lU= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.24.1/go.mod h1:UFO9jC3njhKdD/ymLnaKi7Or5miVWq06LvRWQNFfnTU= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.48.1 h1:oTX4vsorBZo/Zdum6OKPA4o7544hm6smoRv1QjpTwGo= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.48.1/go.mod h1:0wEl7vrAD8mehJyohS9HZy+WyEOaQO2mJx86Cvh93kM= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.48.1 h1:8nn+rsCvTq9axyEh382S0PFLBeaFwNsT43IrPWzctRU= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.48.1/go.mod h1:viRWSEhtMZqz1rhwmOVKkWl6SwmVowfL9O2YR5gI2PE= github.com/apache/arrow/go/v15 v15.0.2 h1:60IliRbiyTWCWjERBCkO1W4Qun9svcYoZrSLcyOsMLE= github.com/apache/arrow/go/v15 v15.0.2/go.mod h1:DGXsR3ajT524njufqf95822i+KTh+yea1jass9YXgjA= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -76,8 +88,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/martian/v3 v3.3.3 h1:DIhPTQrbPkgs2yJYdXU/eNACCG5DVQjySNRNlflZ9Fc= github.com/google/martian/v3 v3.3.3/go.mod h1:iEPrYcgCF7jA9OtScMFQyAlZZ4YXTKEtJ1E6RWzmBA0= -github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o= -github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= +github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM= +github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -103,8 +115,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ= github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0= github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0= @@ -113,22 +125,22 @@ go.einride.tech/aip v0.67.1 h1:d/4TW92OxXBngkSOwWS2CH5rez869KpKMaN44mdxkFI= go.einride.tech/aip v0.67.1/go.mod h1:ZGX4/zKw8dcgzdLsrvpOOGxfxI2QSk12SlP7d6c0/XI= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 h1:4Pp6oUg3+e/6M4C0A/3kJ2VYa++dsWVTtGgLVj5xtHg= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0/go.mod h1:Mjt1i1INqiaoZOMGR1RIUJN+i3ChKoFRqzrRQhlkbs0= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw= -go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= -go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= -go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= -go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= -go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw= -go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg= -go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= -go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 h1:9G6E0TXzGFVfTnawRzrPl83iHOAV7L8NJiR8RSGYV1g= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0/go.mod h1:azvtTADFQJA8mX80jIH/akaE7h+dbm/sVuaHqN13w74= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 h1:4K4tsIXefpVJtvA/8srF4V4y0akAoPHkIslgAkjixJA= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0/go.mod h1:jjdQuTGVsXV4vSs+CJ2qYDeDPf9yIJV23qlIzBm73Vg= +go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo= +go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4= +go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q= +go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s= +go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE= +go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg= +go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g= +go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= -golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= @@ -143,29 +155,29 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= -golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= -golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= +golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= -golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U= +golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -178,19 +190,19 @@ golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSm golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= gonum.org/v1/gonum v0.12.0 h1:xKuo6hzt+gMav00meVPUlXwSdoEJP46BR+wdxQEFK2o= gonum.org/v1/gonum v0.12.0/go.mod h1:73TDxJfAAHeA8Mk9mf8NlIppyhQNo5GLTcYeqgo2lvY= -google.golang.org/api v0.189.0 h1:equMo30LypAkdkLMBqfeIqtyAnlyig1JSZArl4XPwdI= -google.golang.org/api v0.189.0/go.mod h1:FLWGJKb0hb+pU2j+rJqwbnsF+ym+fQs73rbJ+KAUgy8= +google.golang.org/api v0.193.0 h1:eOGDoJFsLU+HpCBaDJex2fWiYujAw9KbXgpOAMePoUs= +google.golang.org/api v0.193.0/go.mod h1:Po3YMV1XZx+mTku3cfJrlIYR03wiGrCOsdpC67hjZvw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20240722135656-d784300faade h1:lKFsS7wpngDgSCeFn7MoLy+wBDQZ1UQIJD4UNM1Qvkg= -google.golang.org/genproto v0.0.0-20240722135656-d784300faade/go.mod h1:FfBgJBJg9GcpPvKIuHSZ/aE1g2ecGL74upMzGZjiGEY= -google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d h1:kHjw/5UfflP/L5EbledDrcG4C2597RtymmGRZvHiCuY= -google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d/go.mod h1:mw8MG/Qz5wfgYr6VqVCiZcHe/GJEfI+oGGDCohaVgB0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240722135656-d784300faade h1:oCRSWfwGXQsqlVdErcyTt4A93Y8fo0/9D4b1gnI++qo= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240722135656-d784300faade/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= +google.golang.org/genproto v0.0.0-20240820151423-278611b39280 h1:oKt8r1ZvaPqBe3oeGTdyx1iNjuBS+VJcc9QdU1CD3d8= +google.golang.org/genproto v0.0.0-20240820151423-278611b39280/go.mod h1:wxEc5TmU9JSLs1rSqG4z1YzeSNigp/9yIojIPuZVvKQ= +google.golang.org/genproto/googleapis/api v0.0.0-20240820151423-278611b39280 h1:YDFM9oOjiFhaMAVgbDxfxW+66nRrsvzQzJ51wp3OxC0= +google.golang.org/genproto/googleapis/api v0.0.0-20240820151423-278611b39280/go.mod h1:fO8wJzT2zbQbAjbIoos1285VfEIYKDDY+Dt+WpTkh6g= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240820151423-278611b39280 h1:XQMA2e105XNlEZ8NRF0HqnUOZzP14sUSsgL09kpdNnU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240820151423-278611b39280/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= diff --git a/pubsub/subscriptions/pull_otel_tracing.go b/pubsub/subscriptions/pull_otel_tracing.go new file mode 100644 index 0000000000..16bedcf450 --- /dev/null +++ b/pubsub/subscriptions/pull_otel_tracing.go @@ -0,0 +1,98 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package subscriptions + +// [START pubsub_subscribe_otel_tracing] +import ( + "context" + "fmt" + "io" + "sync/atomic" + "time" + + "cloud.google.com/go/pubsub" + texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/sdk/resource" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + semconv "go.opentelemetry.io/otel/semconv/v1.24.0" + "google.golang.org/api/option" +) + +func subscribeOpenTelemetryTracing(w io.Writer, projectID, subID string, sampleRate float64) error { + // projectID := "my-project-id" + // subID := "my-sub" + // sampleRate := "1.0" + ctx := context.Background() + + exporter, err := texporter.New(texporter.WithProjectID(projectID), + // Disable spans created by the exporter. + texporter.WithTraceClientOptions( + []option.ClientOption{option.WithTelemetryDisabled()}, + ), + ) + if err != nil { + return fmt.Errorf("error instantiating exporter: %w", err) + } + + resources := resource.NewWithAttributes( + semconv.SchemaURL, + semconv.ServiceNameKey.String("subscriber"), + ) + + // Instantiate a tracer provider with the following settings + tp := sdktrace.NewTracerProvider( + sdktrace.WithBatcher(exporter), + sdktrace.WithResource(resources), + sdktrace.WithSampler( + sdktrace.ParentBased(sdktrace.TraceIDRatioBased(sampleRate)), + ), + ) + + defer tp.ForceFlush(ctx) // flushes any pending spans + otel.SetTracerProvider(tp) + + // Create a new client with tracing enabled. + client, err := pubsub.NewClientWithConfig(ctx, projectID, &pubsub.ClientConfig{ + EnableOpenTelemetryTracing: true, + }) + if err != nil { + return fmt.Errorf("pubsub.NewClient: %w", err) + } + defer client.Close() + + sub := client.Subscription(subID) + + // Receive messages for 10 seconds, which simplifies testing. + // Comment this out in production, since `Receive` should + // be used as a long running operation. + ctx, cancel := context.WithTimeout(ctx, 10*time.Second) + defer cancel() + + var received int32 + err = sub.Receive(ctx, func(_ context.Context, msg *pubsub.Message) { + fmt.Fprintf(w, "Got message: %q\n", string(msg.Data)) + atomic.AddInt32(&received, 1) + msg.Ack() + }) + if err != nil { + return fmt.Errorf("sub.Receive: %w", err) + } + fmt.Fprintf(w, "Received %d messages\n", received) + + return nil +} + +// [END pubsub_subscribe_otel_tracing] diff --git a/pubsub/subscriptions/subscription_test.go b/pubsub/subscriptions/subscription_test.go index ad588fc63b..97cd43c93a 100644 --- a/pubsub/subscriptions/subscription_test.go +++ b/pubsub/subscriptions/subscription_test.go @@ -29,7 +29,10 @@ import ( "cloud.google.com/go/bigquery" "cloud.google.com/go/iam" "cloud.google.com/go/pubsub" + "cloud.google.com/go/pubsub/pstest" "cloud.google.com/go/storage" + trace "cloud.google.com/go/trace/apiv1" + "cloud.google.com/go/trace/apiv1/tracepb" "google.golang.org/api/iterator" "github.com/GoogleCloudPlatform/golang-samples/internal/testutil" @@ -987,6 +990,73 @@ func TestOptimisticSubscribe(t *testing.T) { }) } +func TestSubscribeOpenTelemetryTracing(t *testing.T) { + tc := testutil.SystemTest(t) + buf := new(bytes.Buffer) + ctx := context.Background() + + // Use the pstest fake with emulator settings. + srv := pstest.NewServer() + t.Setenv("PUBSUB_EMULATOR_HOST", srv.Addr) + client := setup(t) + + otelTopicID := topicID + "-otel" + otelSubID := subID + "-otel" + + topic, err := client.CreateTopic(ctx, otelTopicID) + if err != nil { + t.Fatalf("failed to create topic: %v", err) + } + defer topic.Delete(ctx) + + if err := create(buf, tc.ProjectID, otelSubID, topic); err != nil { + t.Fatalf("failed to create a topic: %v", err) + } + defer client.Subscription(otelSubID).Delete(ctx) + + if err := publishMsgs(ctx, topic, 1); err != nil { + t.Fatalf("failed to publish setup message: %v", err) + } + + if err := subscribeOpenTelemetryTracing(buf, tc.ProjectID, otelSubID, 1.0); err != nil { + t.Fatalf("failed to subscribe message with otel tracing: %v", err) + } + got := buf.String() + want := "Received 1 message" + if !strings.Contains(got, want) { + t.Fatalf("expected 1 message, got: %s", got) + } + + traceClient, err := trace.NewClient(ctx) + if err != nil { + t.Fatalf("trace client instantiation: %v", err) + } + + testutil.Retry(t, 3, time.Second, func(r *testutil.R) { + // Wait some time for the spans to show up in Cloud Trace. + time.Sleep(5 * time.Second) + iter := traceClient.ListTraces(ctx, &tracepb.ListTracesRequest{ + ProjectId: tc.ProjectID, + Filter: fmt.Sprintf("+messaging.destination.name:%v", otelSubID), + }) + numTrace := 0 + for { + _, err := iter.Next() + if err == iterator.Done { + break + } + if err != nil { + r.Errorf("got err in iter.Next: %v", err) + } + numTrace++ + } + // Three traces are created from subscribe side: subscribe, ack, modack spans. + if want := 3; numTrace != want { + r.Errorf("got %d traces, want %d", numTrace, want) + } + }) +} + func publishMsgs(ctx context.Context, t *pubsub.Topic, numMsgs int) error { var results []*pubsub.PublishResult for i := 0; i < numMsgs; i++ { diff --git a/pubsub/topics/publish_otel_tracing.go b/pubsub/topics/publish_otel_tracing.go new file mode 100644 index 0000000000..c18a6e6976 --- /dev/null +++ b/pubsub/topics/publish_otel_tracing.go @@ -0,0 +1,87 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package topics + +// [START pubsub_publish_otel_tracing] +import ( + "context" + "fmt" + "io" + + "cloud.google.com/go/pubsub" + "go.opentelemetry.io/otel" + "google.golang.org/api/option" + + texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace" + "go.opentelemetry.io/otel/sdk/resource" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + semconv "go.opentelemetry.io/otel/semconv/v1.26.0" +) + +// publishOpenTelemetryTracing publishes a single message with OpenTelemetry tracing +// enabled, exporting to Cloud Trace. +func publishOpenTelemetryTracing(w io.Writer, projectID, topicID string, sampling float64) error { + // projectID := "my-project-id" + // topicID := "my-topic" + ctx := context.Background() + + exporter, err := texporter.New(texporter.WithProjectID(projectID), + // Disable spans created by the exporter. + texporter.WithTraceClientOptions( + []option.ClientOption{option.WithTelemetryDisabled()}, + ), + ) + if err != nil { + return fmt.Errorf("error instantiating exporter: %w", err) + } + + resources := resource.NewWithAttributes( + semconv.SchemaURL, + semconv.ServiceNameKey.String("publisher"), + ) + + // Instantiate a tracer provider with the following settings + tp := sdktrace.NewTracerProvider( + sdktrace.WithBatcher(exporter), + sdktrace.WithResource(resources), + sdktrace.WithSampler( + sdktrace.ParentBased(sdktrace.TraceIDRatioBased(sampling)), + ), + ) + + defer tp.ForceFlush(ctx) // flushes any pending spans + otel.SetTracerProvider(tp) + + // Create a new client with tracing enabled. + client, err := pubsub.NewClientWithConfig(ctx, projectID, &pubsub.ClientConfig{ + EnableOpenTelemetryTracing: true, + }) + if err != nil { + return fmt.Errorf("pubsub: NewClient: %w", err) + } + defer client.Close() + + t := client.Topic(topicID) + result := t.Publish(ctx, &pubsub.Message{ + Data: []byte("Publishing message with tracing"), + }) + if _, err := result.Get(ctx); err != nil { + return fmt.Errorf("pubsub: result.Get: %w", err) + } + fmt.Fprintln(w, "Published a traced message") + return nil +} + +// [END pubsub_publish_otel_tracing] diff --git a/pubsub/topics/topics_test.go b/pubsub/topics/topics_test.go index f44040f516..e4aac8a892 100644 --- a/pubsub/topics/topics_test.go +++ b/pubsub/topics/topics_test.go @@ -30,6 +30,8 @@ import ( "cloud.google.com/go/iam" "cloud.google.com/go/pubsub" "cloud.google.com/go/pubsub/pstest" + trace "cloud.google.com/go/trace/apiv1" + "cloud.google.com/go/trace/apiv1/tracepb" "github.com/GoogleCloudPlatform/golang-samples/internal/testutil" "google.golang.org/api/iterator" ) @@ -313,3 +315,59 @@ func TestTopicKinesis(t *testing.T) { t.Fatalf("failed to update a topic type to kinesis ingestion: %v", err) } } + +func TestPublishOpenTelemetryTracing(t *testing.T) { + tc := testutil.SystemTest(t) + buf := new(bytes.Buffer) + ctx := context.Background() + + // Use the pstest fake with emulator settings. + srv := pstest.NewServer() + t.Setenv("PUBSUB_EMULATOR_HOST", srv.Addr) + setup(t) + + otelTopicID := topicID + "-otel" + + if err := create(buf, tc.ProjectID, otelTopicID); err != nil { + t.Fatalf("failed to create topic: %v", err) + } + defer delete(buf, tc.ProjectID, otelTopicID) + + if err := publishOpenTelemetryTracing(buf, tc.ProjectID, otelTopicID, 1.0); err != nil { + t.Fatalf("failed to publish message with otel tracing: %v", err) + } + got := buf.String() + want := "Published a traced message" + if !strings.Contains(got, want) { + t.Fatalf("failed to publish message:\n got: %v", got) + } + + traceClient, err := trace.NewClient(ctx) + if err != nil { + t.Fatalf("trace client instantiation: %v", err) + } + + testutil.Retry(t, 3, time.Second, func(r *testutil.R) { + // Wait some time for the spans to show up in Cloud Trace. + time.Sleep(5 * time.Second) + iter := traceClient.ListTraces(ctx, &tracepb.ListTracesRequest{ + ProjectId: tc.ProjectID, + Filter: fmt.Sprintf("+messaging.destination.name:%v", otelTopicID), + }) + numTrace := 0 + for { + _, err := iter.Next() + if err == iterator.Done { + break + } + if err != nil { + r.Errorf("got err in iter.Next: %v", err) + } + numTrace++ + } + // Two traces are expected: create and (batch) publish traces. + if want := 2; numTrace != want { + r.Errorf("got %d traces, want %d", numTrace, want) + } + }) +}