Skip to content

Commit 5fc0b13

Browse files
authored
Merge branch 'main' into tpu_queued_resources_startup_script
2 parents 954e4ec + 22a46bd commit 5fc0b13

37 files changed

+2059
-562
lines changed

.github/blunderbuss.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ assign_issues_by:
2626
- labels:
2727
- 'api: cloudsql'
2828
to:
29-
- GoogleCloudPlatform/infra-db-sdk
29+
- GoogleCloudPlatform/cloud-sql-connectors
3030
- labels:
3131
- 'api: dlp'
3232
to:
@@ -55,7 +55,7 @@ assign_prs_by:
5555
- labels:
5656
- 'api: cloudsql'
5757
to:
58-
- GoogleCloudPlatform/infra-db-sdk
58+
- GoogleCloudPlatform/cloud-sql-connectors
5959
- labels:
6060
- 'api: dlp'
6161
to:

.github/cloud-samples-tools/cmd/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ func affectedCmd(configFile string, diffsFile string) {
7272
if err != nil {
7373
log.Fatalln("❌ error getting the diffs: ", diffsFile, "\n", err)
7474
}
75-
diffs := strings.Split(string(diffsBytes), "\n")
75+
// Trim whitespace to remove extra newline from diff output.
76+
diffs := strings.Split(strings.TrimSpace(string(diffsBytes)), "\n")
7677

77-
packages, err := config.Affected(diffs)
78+
// Log to stderr since GitHub Actions expects the output on stdout.
79+
packages, err := config.Affected(os.Stderr, diffs)
7880
if err != nil {
7981
log.Fatalln("❌ error finding the affected packages.\n", err)
8082
}

.github/cloud-samples-tools/pkg/config/config.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package config
1919
import (
2020
"encoding/json"
2121
"errors"
22+
"fmt"
23+
"io"
2224
"io/fs"
2325
"os"
2426
"path/filepath"
@@ -154,8 +156,8 @@ func (c *Config) FindAllPackages(root string) ([]string, error) {
154156
// Affected returns the packages that have been affected from diffs.
155157
// If there are diffs on at leat one global file affecting all packages,
156158
// then this returns all packages matched by the config.
157-
func (c *Config) Affected(diffs []string) ([]string, error) {
158-
changed := c.Changed(diffs)
159+
func (c *Config) Affected(log io.Writer, diffs []string) ([]string, error) {
160+
changed := c.Changed(log, diffs)
159161
if slices.Contains(changed, ".") {
160162
return c.FindAllPackages(".")
161163
}
@@ -165,16 +167,13 @@ func (c *Config) Affected(diffs []string) ([]string, error) {
165167
// Changed returns the packages that have changed.
166168
// It only returns packages that are matched by the config,
167169
// and are not excluded by the config.
168-
func (c *Config) Changed(diffs []string) []string {
170+
func (c *Config) Changed(log io.Writer, diffs []string) []string {
169171
changedUnique := make(map[string]bool)
170172
for _, diff := range diffs {
171173
if !c.Matches(diff) {
172174
continue
173175
}
174176
pkg := c.FindPackage(diff)
175-
if slices.Contains(c.ExcludePackages, pkg) {
176-
continue
177-
}
178177
changedUnique[pkg] = true
179178
}
180179

@@ -184,6 +183,10 @@ func (c *Config) Changed(diffs []string) []string {
184183

185184
changed := make([]string, 0, len(changedUnique))
186185
for pkg := range changedUnique {
186+
if slices.Contains(c.ExcludePackages, pkg) {
187+
fmt.Fprintf(log, "ℹ️ Excluded package %q, skipping.\n", pkg)
188+
continue
189+
}
187190
changed = append(changed, pkg)
188191
}
189192
return changed

.github/cloud-samples-tools/pkg/config/config_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,30 +167,35 @@ func TestFindPackage(t *testing.T) {
167167

168168
func TestChanged(t *testing.T) {
169169
config := c.Config{
170-
PackageFile: []string{"package.json"},
171-
Match: []string{"*"},
170+
PackageFile: []string{"package.json"},
171+
Match: []string{"*"},
172+
ExcludePackages: []string{filepath.Join("testdata", "excluded")},
172173
}
173174

174175
tests := []struct {
175176
diffs []string
176177
expected []string
177178
}{
178-
{
179+
{ // Global change, everything is affected.
179180
diffs: []string{filepath.Join("testdata", "file.txt")},
180181
expected: []string{"."},
181182
},
182-
{
183+
{ // Single affected package.
183184
diffs: []string{filepath.Join("testdata", "my-package", "file.txt")},
184185
expected: []string{filepath.Join("testdata", "my-package")},
185186
},
186-
{
187+
{ // Single affected nested package.
187188
diffs: []string{filepath.Join("testdata", "my-package", "subpackage", "file.txt")},
188189
expected: []string{filepath.Join("testdata", "my-package", "subpackage")},
189190
},
191+
{ // Excluded package.
192+
diffs: []string{filepath.Join("testdata", "excluded", "file.txt")},
193+
expected: []string{},
194+
},
190195
}
191196

192197
for _, test := range tests {
193-
got := config.Changed(test.diffs)
198+
got := config.Changed(os.Stderr, test.diffs)
194199
if !reflect.DeepEqual(test.expected, got) {
195200
t.Fatal("expected equal\n", test.expected, got)
196201
}

.github/cloud-samples-tools/pkg/config/testdata/excluded/package.json

Whitespace-only changes.

.github/workflows/monitoring-opencensus.yaml

Lines changed: 0 additions & 52 deletions
This file was deleted.

.github/workflows/opencensus.yaml

Lines changed: 0 additions & 52 deletions
This file was deleted.

.github/workflows/utils/workflows.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@
7878
"media/transcoder",
7979
"media/video-stitcher",
8080
"mediatranslation",
81-
"monitoring/opencensus",
8281
"monitoring/prometheus",
8382
"monitoring/snippets",
84-
"opencensus",
8583
"retail",
8684
"run/filesystem",
8785
"scheduler",

CODEOWNERS

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ tpu @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers
2929
webrisk @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
3030

3131
# SoDa teams
32-
cloud-sql @GoogleCloudPlatform/infra-db-sdk @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
32+
cloud-sql @GoogleCloudPlatform/cloud-sql-connectors @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
3333
datastore @GoogleCloudPlatform/cloud-native-db-dpes @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
3434
storagetransfer @GoogleCloudPlatform/cloud-storage-dpes @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
3535

3636
# One-offs
3737
composer @GoogleCloudPlatform/cloud-dpes-composer @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
38-
monitoring/opencensus @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
3938

4039
# Data & AI
4140
document-ai @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/document-ai-samples-contributors @GoogleCloudPlatform/cloud-samples-reviewers
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
async function main(projectId, inputUri, outputUri, jobName) {
20+
// [START generativeaionvertexai_embedding_batch]
21+
// Imports the aiplatform library
22+
const aiplatformLib = require('@google-cloud/aiplatform');
23+
const aiplatform = aiplatformLib.protos.google.cloud.aiplatform.v1;
24+
25+
/**
26+
* TODO(developer): Uncomment/update these variables before running the sample.
27+
*/
28+
// projectId = 'YOUR_PROJECT_ID';
29+
30+
// Optional: URI of the input dataset.
31+
// Could be a BigQuery table or a Google Cloud Storage file.
32+
// E.g. "gs://[BUCKET]/[DATASET].jsonl" OR "bq://[PROJECT].[DATASET].[TABLE]"
33+
// inputUri =
34+
// 'gs://cloud-samples-data/generative-ai/embeddings/embeddings_input.jsonl';
35+
36+
// Optional: URI where the output will be stored.
37+
// Could be a BigQuery table or a Google Cloud Storage file.
38+
// E.g. "gs://[BUCKET]/[OUTPUT].jsonl" OR "bq://[PROJECT].[DATASET].[TABLE]"
39+
// outputUri = 'gs://your_bucket/embedding_batch_output';
40+
41+
// The name of the job
42+
// jobName = `Batch embedding job: ${new Date().getMilliseconds()}`;
43+
44+
const textEmbeddingModel = 'text-embedding-005';
45+
const location = 'us-central1';
46+
47+
// Configure the parent resource
48+
const parent = `projects/${projectId}/locations/${location}`;
49+
const modelName = `projects/${projectId}/locations/${location}/publishers/google/models/${textEmbeddingModel}`;
50+
51+
// Specifies the location of the api endpoint
52+
const clientOptions = {
53+
apiEndpoint: `${location}-aiplatform.googleapis.com`,
54+
};
55+
56+
// Instantiates a client
57+
const jobServiceClient = new aiplatformLib.JobServiceClient(clientOptions);
58+
59+
// Generates embeddings from text using batch processing.
60+
// Read more: https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/batch-prediction-genai-embeddings
61+
async function callBatchEmbedding() {
62+
const gcsSource = new aiplatform.GcsSource({
63+
uris: [inputUri],
64+
});
65+
66+
const inputConfig = new aiplatform.BatchPredictionJob.InputConfig({
67+
gcsSource,
68+
instancesFormat: 'jsonl',
69+
});
70+
71+
const gcsDestination = new aiplatform.GcsDestination({
72+
outputUriPrefix: outputUri,
73+
});
74+
75+
const outputConfig = new aiplatform.BatchPredictionJob.OutputConfig({
76+
gcsDestination,
77+
predictionsFormat: 'jsonl',
78+
});
79+
80+
const batchPredictionJob = new aiplatform.BatchPredictionJob({
81+
displayName: jobName,
82+
model: modelName,
83+
inputConfig,
84+
outputConfig,
85+
});
86+
87+
const request = {
88+
parent,
89+
batchPredictionJob,
90+
};
91+
92+
// Create batch prediction job request
93+
const [response] = await jobServiceClient.createBatchPredictionJob(request);
94+
95+
console.log('Raw response: ', JSON.stringify(response, null, 2));
96+
}
97+
98+
await callBatchEmbedding();
99+
// [END generativeaionvertexai_embedding_batch]
100+
}
101+
102+
main(...process.argv.slice(2)).catch(err => {
103+
console.error(err.message);
104+
process.exitCode = 1;
105+
});

0 commit comments

Comments
 (0)