Skip to content
Merged
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ Every service links to its own page with a coverage breakdown — audited operat
| [RDS Data](services/rdsdata/README.md) | A | 7 | 4 structural gaps |
| [Redshift](services/redshift/README.md) | A | 9 | 5 structural gaps |
| [Redshift Data](services/redshiftdata/README.md) | A | 12 | 4 structural gaps; 1 deferred |
| [Timestream Query](services/timestreamquery/README.md) | A | 12 | 4 gaps; 1 structural gap |
| [Timestream Query](services/timestreamquery/README.md) | A | 12 | 3 gaps; 1 structural gap |
| [Timestream Write](services/timestreamwrite/README.md) | A | 19 | 1 structural gap |

### Networking & Content Delivery
Expand Down
2 changes: 1 addition & 1 deletion internal/app/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3141,7 +3141,7 @@ func TestLocalstackCompatibilityEndpoints(t *testing.T) {

waitForServerReady(t, port)

client := &http.Client{Timeout: 2 * time.Second}
client := &http.Client{Transport: testclient.New(t).Transport, Timeout: 2 * time.Second}

tests := []struct {
validate func(t *testing.T, body map[string]any)
Expand Down
5 changes: 4 additions & 1 deletion internal/app/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"time"

"github.com/stretchr/testify/require"

"github.com/blackbirdworks/gopherstack/pkgs/httpclient"
)

func TestMultipleServersStartupAndShutdown(t *testing.T) {
Expand Down Expand Up @@ -109,7 +111,8 @@ func startServerRetryingPort(t *testing.T, demo bool) (int, chan struct{}, chan
// exits (delivering to errChan), or the deadline elapses. Matching the per-attempt account ID proves
// the responder is this attempt's server, not another test's server that grabbed the port first.
func waitForInstance(port int, accountID string, errChan <-chan error, timeout, interval time.Duration) (bool, error) {
client := &http.Client{Timeout: 1 * time.Second}
client := httpclient.New(1 * time.Second)
defer client.CloseIdleConnections()
deadline := time.Now().Add(timeout)
ticker := time.NewTicker(interval)
defer ticker.Stop()
Expand Down
67 changes: 67 additions & 0 deletions internal/app/timestream_query_sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,70 @@ func TestTimestreamQuery_SDK_ScheduledQueryWritesTarget(t *testing.T) {
assert.EqualValues(t, 2, desc.ScheduledQuery.LastRunSummary.ExecutionStats.RecordsIngested)
assert.EqualValues(t, 2, desc.ScheduledQuery.LastRunSummary.ExecutionStats.QueryResultRows)
}

func TestTimestreamQuery_SDK_InsightsUsePartitionKey(t *testing.T) {
t.Parallel()

tests := []struct {
key twtypes.PartitionKey
name string
query string
note string
wantKey []string
wantCov float64
}{
{
name: "dimension key",
key: twtypes.PartitionKey{Type: twtypes.PartitionKeyTypeDimension, Name: aws.String("host")},
query: "SELECT * FROM pkdb.m WHERE host = 'h1'",
wantKey: []string{"host"}, wantCov: 0.5, note: "constrained",
},
{
name: "measure key",
key: twtypes.PartitionKey{Type: twtypes.PartitionKeyTypeMeasure},
query: "SELECT * FROM pkdb.m WHERE measure_name = 'cpu'",
wantKey: []string{"measure_name"}, wantCov: 1, note: "all measures are cpu",
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

t0 := time.Date(2026, 10, 31, 12, 0, 0, 0, time.UTC)
env := newTimestreamEnv(t, t0)

_, err := env.write.CreateDatabase(
t.Context(),
&twsdk.CreateDatabaseInput{DatabaseName: aws.String("pkdb")},
)
require.NoError(t, err)

_, err = env.write.CreateTable(t.Context(), &twsdk.CreateTableInput{
DatabaseName: aws.String("pkdb"), TableName: aws.String("m"),
Schema: &twtypes.Schema{CompositePartitionKey: []twtypes.PartitionKey{tc.key}},
})
require.NoError(t, err)

_, err = env.write.WriteRecords(t.Context(), &twsdk.WriteRecordsInput{
DatabaseName: aws.String("pkdb"), TableName: aws.String("m"),
Records: []twtypes.Record{
single("cpu", "1", twtypes.MeasureValueTypeDouble, t0.Add(-time.Minute), dim("host", "h1")),
single("cpu", "2", twtypes.MeasureValueTypeDouble, t0.Add(-time.Minute), dim("host", "h2")),
},
})
require.NoError(t, err)

out, err := env.query.Query(t.Context(), &tqsdk.QueryInput{
QueryString: aws.String(tc.query),
QueryInsights: &tqtypes.QueryInsights{Mode: tqtypes.QueryInsightsModeEnabledWithRateControl},
})
require.NoError(t, err)
require.NotNil(t, out.QueryInsightsResponse.QuerySpatialCoverage)

cov := out.QueryInsightsResponse.QuerySpatialCoverage.Max
assert.Equal(t, tc.wantKey, cov.PartitionKey)
assert.InDelta(t, tc.wantCov, cov.Value, 0.001, tc.note)
})
}
}
28 changes: 26 additions & 2 deletions internal/app/timestream_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ type timestreamRecordSource struct {
}

var (
_ timestreamquerybackend.RecordSource = (*timestreamRecordSource)(nil)
_ timestreamquerybackend.SchemaSource = (*timestreamRecordSource)(nil)
_ timestreamquerybackend.RecordSource = (*timestreamRecordSource)(nil)
_ timestreamquerybackend.SchemaSource = (*timestreamRecordSource)(nil)
_ timestreamquerybackend.PartitionKeySource = (*timestreamRecordSource)(nil)
)

func newTimestreamRecordSource(h *timestreamwritebackend.Handler) *timestreamRecordSource {
Expand Down Expand Up @@ -69,6 +70,29 @@ func (s *timestreamRecordSource) TableShapes(region, database, table string) []t
return out
}

// TablePartitionKeys returns the table's customer-defined partition key: dimension names, or measure_name for a
// measure key, in schema order.
func (s *timestreamRecordSource) TablePartitionKeys(region, database, table string) []string {
tbl, err := s.handler.BackendFor(region).DescribeTable(database, table)
if err != nil || tbl.Schema == nil {
return nil
}

keys := make([]string, 0, len(tbl.Schema.CompositePartitionKey))

for _, pk := range tbl.Schema.CompositePartitionKey {
if pk.Type == timestreamwritebackend.PartitionKeyTypeMeasure {
keys = append(keys, "measure_name")

continue
}

keys = append(keys, pk.Name)
}

return keys
}

func (s *timestreamRecordSource) ListDatabases(region string) []string {
dbs := s.handler.BackendFor(region).ListDatabases()
names := make([]string, 0, len(dbs))
Expand Down
11 changes: 11 additions & 0 deletions pkgs/persistence/testdata/snapshot_inventory.json
Original file line number Diff line number Diff line change
Expand Up @@ -38327,6 +38327,8 @@
"QueryInsightsResponse.OutputRows int64 `json:\"OutputRows\"`",
"QueryInsightsResponse.QuerySpatialCoverage float64 `json:\"QuerySpatialCoverage,omitempty\"`",
"QueryInsightsResponse.QueryTableCount int64 `json:\"QueryTableCount\"`",
"QueryInsightsResponse.SpatialCoverage *QuerySpatialCoverage `json:\"spatial_coverage,omitempty\"`",
"QueryInsightsResponse.TemporalRange *QueryTemporalRange `json:\"temporal_range,omitempty\"`",
"QueryInsightsResponse.UnloadPartitionCount int64 `json:\"UnloadPartitionCount,omitempty\"`",
"QueryInsightsResponse.UnloadWrittenBytes int64 `json:\"UnloadWrittenBytes,omitempty\"`",
"QueryInsightsResponse.UnloadWrittenRows int64 `json:\"UnloadWrittenRows,omitempty\"`",
Expand All @@ -38336,9 +38338,16 @@
"QueryResult.QueryID string",
"QueryResult.QueryStatus QueryStatusDetail",
"QueryResult.Rows []Row",
"QuerySpatialCoverage.Max *QuerySpatialCoverageMax `json:\"Max,omitempty\"`",
"QuerySpatialCoverageMax.PartitionKey []string `json:\"PartitionKey\"`",
"QuerySpatialCoverageMax.TableArn string `json:\"TableArn\"`",
"QuerySpatialCoverageMax.Value float64 `json:\"Value\"`",
"QueryStatusDetail.CumulativeBytesMetered int64 `json:\"CumulativeBytesMetered\"`",
"QueryStatusDetail.CumulativeBytesScanned int64 `json:\"CumulativeBytesScanned\"`",
"QueryStatusDetail.ProgressPercentage float64 `json:\"ProgressPercentage\"`",
"QueryTemporalRange.Max *QueryTemporalRangeMax `json:\"Max,omitempty\"`",
"QueryTemporalRangeMax.TableArn string `json:\"TableArn\"`",
"QueryTemporalRangeMax.Value int64 `json:\"Value\"`",
"Row.Data []Datum `json:\"Data\"`",
"S3ReportLocation.BucketName string `json:\"BucketName,omitempty\"`",
"S3ReportLocation.ObjectKey string `json:\"ObjectKey,omitempty\"`",
Expand Down Expand Up @@ -38369,7 +38378,9 @@
"ScheduledQuery.TargetTable string `json:\"target_table\"`",
"ScheduledQueryInsightsResponse.OutputBytes int64 `json:\"OutputBytes\"`",
"ScheduledQueryInsightsResponse.OutputRows int64 `json:\"OutputRows\"`",
"ScheduledQueryInsightsResponse.QuerySpatialCoverage *QuerySpatialCoverage `json:\"QuerySpatialCoverage,omitempty\"`",
"ScheduledQueryInsightsResponse.QueryTableCount int64 `json:\"QueryTableCount\"`",
"ScheduledQueryInsightsResponse.QueryTemporalRange *QueryTemporalRange `json:\"QueryTemporalRange,omitempty\"`",
"ScheduledQueryTargetDetail.DimensionMappings []DimensionMapping",
"ScheduledQueryTargetDetail.MeasureNameColumn string",
"ScheduledQueryTargetDetail.MixedMeasureMappings []MixedMeasureMapping",
Expand Down
3 changes: 2 additions & 1 deletion services/azurefunctions/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/blackbirdworks/gopherstack/pkgs/testclient"
"github.com/blackbirdworks/gopherstack/services/azurefunctions"
)

Expand All @@ -34,7 +35,7 @@ func newEnv(t *testing.T, withRuntime bool) *env {
azurefunctions.Settings{Domain: testDomain, Port: azurefunctions.DefaultPort, StartupTimeout: 20 * time.Second},
)

e := &env{backend: b, client: &http.Client{Timeout: 30 * time.Second}}
e := &env{backend: b, client: &http.Client{Transport: testclient.New(t).Transport, Timeout: 30 * time.Second}}

if withRuntime {
e.rt = newFakeRuntime()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
"github.com/blackbirdworks/gopherstack/pkgs/testclient"
"github.com/blackbirdworks/gopherstack/services/cloudformation"
lambdabackend "github.com/blackbirdworks/gopherstack/services/lambda"
)
Expand Down Expand Up @@ -64,7 +65,7 @@ func TestResourceCreator_CustomResource_DeleteEvent(t *testing.T) {
"PhysicalResourceId": ev.PhysicalResourceID,
}
body, _ := json.Marshal(resp, jsonx.V1())
client := &http.Client{Timeout: 2 * time.Second}
client := &http.Client{Transport: testclient.New(t).Transport, Timeout: 2 * time.Second}
req, reqErr := http.NewRequestWithContext(
ctx,
http.MethodPut,
Expand Down Expand Up @@ -159,7 +160,7 @@ func TestResourceCreator_CustomResource_UpdateEvent(t *testing.T) {
"PhysicalResourceId": ev.PhysicalResourceID,
}
body, _ := json.Marshal(resp, jsonx.V1())
client := &http.Client{Timeout: 2 * time.Second}
client := &http.Client{Transport: testclient.New(t).Transport, Timeout: 2 * time.Second}
req, reqErr := http.NewRequestWithContext(
ctx,
http.MethodPut,
Expand Down Expand Up @@ -268,7 +269,7 @@ func TestStack_CustomResource_UpdateStack_SendsUpdateEvent(t *testing.T) {
"PhysicalResourceId": physID,
}
body, _ := json.Marshal(resp, jsonx.V1())
client := &http.Client{Timeout: 2 * time.Second}
client := &http.Client{Transport: testclient.New(t).Transport, Timeout: 2 * time.Second}
req, reqErr := http.NewRequestWithContext(
ctx,
http.MethodPut,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
"github.com/blackbirdworks/gopherstack/pkgs/page"
"github.com/blackbirdworks/gopherstack/pkgs/testclient"
"github.com/blackbirdworks/gopherstack/services/cloudformation"
lambdabackend "github.com/blackbirdworks/gopherstack/services/lambda"
)
Expand Down Expand Up @@ -162,7 +163,7 @@ func TestResourceCreator_CustomResource_ResponseURL_RoundTrip(t *testing.T) {
}

body, _ := json.Marshal(resp, jsonx.V1())
client := &http.Client{}
client := testclient.New(t)
putReq, _ := http.NewRequestWithContext(t.Context(), http.MethodPut, url,
newBytesReader(body))
putReq.ContentLength = int64(len(body))
Expand Down Expand Up @@ -365,7 +366,7 @@ func TestResourceCreator_CustomResource_FAILEDResponse(t *testing.T) {
"PhysicalResourceId": "failing-resource-001",
}
body, _ := json.Marshal(resp, jsonx.V1())
client := &http.Client{}
client := testclient.New(t)
req, _ := http.NewRequestWithContext(t.Context(), http.MethodPut, url, newBytesReader(body))
req.ContentLength = int64(len(body))
res, err := client.Do(req)
Expand Down Expand Up @@ -461,7 +462,7 @@ func TestStack_CustomResource_GetAtt_DataOutputs(t *testing.T) {
},
}
body, _ := json.Marshal(resp, jsonx.V1())
client := &http.Client{}
client := testclient.New(t)
req, _ := http.NewRequestWithContext(t.Context(), http.MethodPut, url, newBytesReader(body))
req.ContentLength = int64(len(body))
res, err := client.Do(req)
Expand Down
Loading
Loading