Skip to content

Commit c3fad2c

Browse files
authored
Fix: disable endpoint discovery when a custom endpoint is set (#475)
1 parent c84baaf commit c3fad2c

File tree

6 files changed

+32
-87
lines changed

6 files changed

+32
-87
lines changed

.vscode/.vscode/launch.json

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

.vscode/.vscode/tasks.json

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

.vscode/launch.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
"type": "go",
77
"request": "launch",
88
"mode": "auto",
9-
"program": "${workspaceFolder}/pkg/main.go",
9+
"program": "${workspaceFolder}/pkg/",
1010
"env": {},
11-
"args": ["--standalone=true"],
12-
"output": "${workspaceFolder}/pkg/__debug_bin"
13-
}
11+
"args": ["--standalone=true"]
12+
},
1413
]
1514
}

pkg/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func main() {
12-
if err := datasource.Manage("timestream-datasource", timestream.NewDatasource, datasource.ManageOpts{}); err != nil {
12+
if err := datasource.Manage("grafana-timestream-datasource", timestream.NewDatasource, datasource.ManageOpts{}); err != nil {
1313
backend.Logger.Error(err.Error())
1414
os.Exit(1)
1515
}

pkg/timestream/datasource.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"github.com/grafana/grafana-aws-sdk/pkg/awsauth"
8-
"github.com/grafana/grafana-plugin-sdk-go/data"
97
"time"
108

9+
"github.com/grafana/grafana-aws-sdk/pkg/awsauth"
1110
"github.com/grafana/grafana-plugin-sdk-go/backend"
1211
sdkhttpclient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
1312
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
1413
"github.com/grafana/grafana-plugin-sdk-go/backend/resource"
14+
"github.com/grafana/grafana-plugin-sdk-go/data"
1515
"github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource"
1616
"github.com/grafana/timestream-datasource/pkg/models"
1717

@@ -63,9 +63,33 @@ func NewDatasource(ctx context.Context, s backend.DataSourceInstanceSettings) (i
6363
return nil, backend.DownstreamError(err)
6464
}
6565

66+
var client QueryClient
67+
if settings.Endpoint != "" && settings.Endpoint != "default" {
68+
client = timestreamquery.NewFromConfig(cfg, func(o *timestreamquery.Options) {
69+
// Why disable Endpoint Discovery when a custom endpoint (e.g., VPC endpoint) is configured?
70+
// - AWS SDK for Go v1: endpoint discovery was OFF by default and only used when endpoint was unset/empty.
71+
// VPC setups worked because DescribeEndpoints was not invoked.
72+
// - AWS SDK for Go v2: endpoint discovery defaults to AUTO. Because Timestream requires discovery,
73+
// the SDK will call DescribeEndpoints before Query. With a custom BaseEndpoint (VPC endpoint),
74+
// DescribeEndpoints is routed through that endpoint, which typically does not implement it,
75+
// resulting in a 404 response.
76+
// - Even forcing discovery through the SDK’s default public resolver can fail if the VPC blocks
77+
// egress to public AWS endpoints.
78+
// To preserve existing customer VPC configurations and avoid breaking changes, we explicitly disable
79+
// endpoint discovery whenever a custom endpoint is provided. Regular operations still use the custom endpoint.
80+
//
81+
// References:
82+
// - v1 behavior (see `EnableEndpointDiscovery` default): https://docs.aws.amazon.com/sdk-for-go/api/aws/
83+
// - v2 EndpointDiscoveryEnableState (AUTO default): https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/aws#EndpointDiscoveryEnableState
84+
o.EndpointDiscovery.EnableEndpointDiscovery = aws.EndpointDiscoveryDisabled
85+
})
86+
} else {
87+
client = timestreamquery.NewFromConfig(cfg)
88+
}
89+
6690
return &timestreamDS{
6791
Settings: settings,
68-
Client: timestreamquery.NewFromConfig(cfg),
92+
Client: client,
6993
}, nil
7094
}
7195

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7799,7 +7799,7 @@ [email protected]:
77997799
prop-types "^15.5.10"
78007800
raf "^3.1.0"
78017801

7802-
"react-data-grid@github:grafana/react-data-grid#de920f0105cb2b7d774444e7443a675f3b568ad6":
7802+
react-data-grid@grafana/react-data-grid#de920f0105cb2b7d774444e7443a675f3b568ad6:
78037803
version "7.0.0-beta.56"
78047804
resolved "https://codeload.github.com/grafana/react-data-grid/tar.gz/de920f0105cb2b7d774444e7443a675f3b568ad6"
78057805
dependencies:

0 commit comments

Comments
 (0)