mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-01-29 17:28:05 -05:00
Adds the following tools for Postgre (1) long_running_transactions - reports transactions that exceed a configured duration threshold. (2) list_locks - lists active locks in the database, including the associated process, lock type, relation, mode, and the query holding or waiting on the lock. (3) replication_stats - reports replication-related metrics for WAL streaming replicas, including lag sizes presented in human-readable form. <img width="3020" height="1420" alt="image" src="https://github.com/user-attachments/assets/e7d70063-b90c-4464-90ec-1bd810c02cac" /> <img width="3036" height="1374" alt="image" src="https://github.com/user-attachments/assets/f7cf584b-ae01-455c-9c9c-acca3166a549" /> <img width="2682" height="868" alt="image" src="https://github.com/user-attachments/assets/dd10646c-4521-4d8f-a111-760d6eb01249" /> ## PR Checklist - [Y] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [Y] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [Y] Ensure the tests and linter pass - [Y] Code coverage does not decrease (if any source code was changed) - [Y] Appropriate docs were updated (if necessary) - [Y] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #1691 #1715 --------- Co-authored-by: Wenxin Du <117315983+duwenxin99@users.noreply.github.com>
96 lines
2.6 KiB
Go
96 lines
2.6 KiB
Go
// Copyright 2025 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
|
|
//
|
|
// http://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 postgresreplicationstats_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
yaml "github.com/goccy/go-yaml"
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/googleapis/genai-toolbox/internal/server"
|
|
"github.com/googleapis/genai-toolbox/internal/testutils"
|
|
"github.com/googleapis/genai-toolbox/internal/tools/postgres/postgresreplicationstats"
|
|
)
|
|
|
|
func TestParseFromYamlPostgresReplicationStats(t *testing.T) {
|
|
ctx, err := testutils.ContextWithNewLogger()
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %s", err)
|
|
}
|
|
tcs := []struct {
|
|
desc string
|
|
in string
|
|
want server.ToolConfigs
|
|
}{
|
|
{
|
|
desc: "basic example",
|
|
in: `
|
|
tools:
|
|
example_tool:
|
|
kind: postgres-replication-stats
|
|
source: my-postgres-instance
|
|
description: some description
|
|
authRequired:
|
|
- my-google-auth-service
|
|
- other-auth-service
|
|
`,
|
|
want: server.ToolConfigs{
|
|
"example_tool": postgresreplicationstats.Config{
|
|
Name: "example_tool",
|
|
Kind: "postgres-replication-stats",
|
|
Source: "my-postgres-instance",
|
|
Description: "some description",
|
|
AuthRequired: []string{"my-google-auth-service", "other-auth-service"},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
desc: "basic example",
|
|
in: `
|
|
tools:
|
|
example_tool:
|
|
kind: postgres-replication-stats
|
|
source: my-postgres-instance
|
|
description: some description
|
|
`,
|
|
want: server.ToolConfigs{
|
|
"example_tool": postgresreplicationstats.Config{
|
|
Name: "example_tool",
|
|
Kind: "postgres-replication-stats",
|
|
Source: "my-postgres-instance",
|
|
Description: "some description",
|
|
AuthRequired: []string{},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
for _, tc := range tcs {
|
|
t.Run(tc.desc, func(t *testing.T) {
|
|
got := struct {
|
|
Tools server.ToolConfigs `yaml:"tools"`
|
|
}{}
|
|
// Parse contents
|
|
err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got)
|
|
if err != nil {
|
|
t.Fatalf("unable to unmarshal: %s", err)
|
|
}
|
|
if diff := cmp.Diff(tc.want, got.Tools); diff != "" {
|
|
t.Fatalf("incorrect parse: diff %v", diff)
|
|
}
|
|
})
|
|
}
|
|
|
|
}
|