Skip to content

Commit b561c90

Browse files
agbishopWitness Patrolclaude
authored
feat: parity batch 19 (SQL engines register functions at init; Timestream function reference and intervals; Athena Trino functions; Service Quotas usage and enforcement) (#2555)
* feat(timestreamquery): the documented function reference, interval arithmetic, non-finite doubles, guarded constants Adds the documented functions the engine lacked (array set operations, zip, repeat, shuffle, base conversion, bit operations, skewness and regression aggregates, n-ary max_by and min_by, weighted percentiles, quantified comparisons, VALUES lists and more) and asserts the reference examples. Intervals add, subtract, scale and compare. NaN and Infinity come out of every producing expression consistently. A constant inside an untaken branch is no longer evaluated. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY * fix: SQL engines register their functions at init under their own prefix; Timestream sequence and interval edge cases The SQLite driver iterates its function table without a lock when a connection opens, so one engine registering lazily while another opened a connection could end the process with a concurrent map fault. Athena, BigQuery and Timestream now register during package init. Timestream's remaining plain-named functions move under its prefix and calls are qualified before execution; a guard and a cross-engine test keep every engine's names apart. Zero-argument sequence and integral calls hung, extreme sequence bounds ran away, a negated year-month interval was zero and log10 was off by one ulp at exact powers of ten. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY * feat(servicequotas): usage and opt-in enforcement for 51 more resource-count quotas CloudWatch Logs, KMS, EventBridge, Step Functions, Route 53, ECR, Auto Scaling, EFS, Firehose, Cognito and the EC2 and VPC resource quotas report live usage. With --enforce-service-quotas the create operations whose API documents a limit error fail at the applied value. Every catalogued quota is classified, and a guard fails when a counted quota has no counter. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY * feat(athena): array set operations, sequence, repeat, zip, base conversion, bit and statistical aggregates and more Trino functions Several of these resolved in Athena only because another engine had registered them under plain names in the shared function table. Athena now implements them itself. Names that are not Trino functions stay unregistered. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY * fix(servicequotas): enforce the documented EC2 limit codes, read the KMS grant limit in the key's Region, pin the refresh delay in the Auto Scaling test EC2 documents limit codes for subnets, internet gateways, security groups and their rules, route tables and vCPUs, so those quotas are enforced under the flag as well as counted. CreateGrant looked up its limit in the request's Region. The instance refresh test raced a fixed 100ms transition. The quota classification data is corrected where a name pattern misfiled entries. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY * fix(athena): an embedding engine keeps the functions it owns and sees none of the standalone-only ones Timestream runs on Athena's translator, which rewrote sequence, repeat, zip, skewness and other names to Athena's new implementations before Timestream could claim them, and exposed Athena-only functions to Timestream queries. The embedded entry point now takes the set of names the host owns and skips standalone-only functions. The Timestream parser no longer reads past the end of a truncated cast. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY * docs: regenerate service READMEs Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY * test(app): split the EC2 quota limit cases into named builders Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY --------- Co-authored-by: Witness Patrol <blackbird7181@gmail.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 2b0616d commit b561c90

142 files changed

Lines changed: 15760 additions & 192 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ Every service links to its own page with a coverage breakdown — audited operat
748748
| [RDS Data](services/rdsdata/README.md) | A | 7 | 4 structural gaps |
749749
| [Redshift](services/redshift/README.md) | A | 9 | 5 structural gaps |
750750
| [Redshift Data](services/redshiftdata/README.md) | A | 12 | 4 structural gaps; 1 deferred |
751-
| [Timestream Query](services/timestreamquery/README.md) | A | 12 | 7 gaps; 1 structural gap |
751+
| [Timestream Query](services/timestreamquery/README.md) | A | 12 | 8 gaps; 1 structural gap |
752752
| [Timestream Write](services/timestreamwrite/README.md) | A | 19 | 1 structural gap |
753753

754754
### Networking & Content Delivery
@@ -794,7 +794,7 @@ Every service links to its own page with a coverage breakdown — audited operat
794794

795795
| Service | Parity | PARITY Entries | Notes |
796796
|---|---|---|---|
797-
| [Athena](services/athena/README.md) | A | 27 | 6 structural gaps; 1 deferred |
797+
| [Athena](services/athena/README.md) | A | 27 | 3 gaps; 6 structural gaps; 1 deferred |
798798
| [Clean Rooms](services/cleanrooms/README.md) | A | — | 18 families; 5 structural gaps |
799799
| [EMR](services/emr/README.md) | A | 65 | 7 structural gaps |
800800
| [EMR Serverless](services/emrserverless/README.md) | A | 22 | 1 structural gap |
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package app
2+
3+
import (
4+
asbackend "github.com/blackbirdworks/gopherstack/services/autoscaling"
5+
cwlogsbackend "github.com/blackbirdworks/gopherstack/services/cloudwatchlogs"
6+
cognitoidentitybackend "github.com/blackbirdworks/gopherstack/services/cognitoidentity"
7+
cognitoidpbackend "github.com/blackbirdworks/gopherstack/services/cognitoidp"
8+
ec2backend "github.com/blackbirdworks/gopherstack/services/ec2"
9+
ecrbackend "github.com/blackbirdworks/gopherstack/services/ecr"
10+
efsbackend "github.com/blackbirdworks/gopherstack/services/efs"
11+
ebbackend "github.com/blackbirdworks/gopherstack/services/eventbridge"
12+
firehosebackend "github.com/blackbirdworks/gopherstack/services/firehose"
13+
kmsbackend "github.com/blackbirdworks/gopherstack/services/kms"
14+
route53backend "github.com/blackbirdworks/gopherstack/services/route53"
15+
sfnbackend "github.com/blackbirdworks/gopherstack/services/stepfunctions"
16+
)
17+
18+
// counted adapts a typed handler read to a quotaCounter; a quota is untracked while its service is not wired.
19+
func counted[H any](read func(h H, account, region string) int) quotaCounter {
20+
return func(a *quotaUsageAdapter, account, region string) (int, bool) {
21+
for _, r := range a.byName {
22+
if h, ok := r.(H); ok {
23+
return read(h, account, region), true
24+
}
25+
}
26+
27+
return 0, false
28+
}
29+
}
30+
31+
func eventsCounted(read func(c ebbackend.QuotaCounter, region string) int) quotaCounter {
32+
return counted(func(h *ebbackend.Handler, _, region string) int {
33+
if c := h.QuotaCounts(); c != nil {
34+
return read(c, region)
35+
}
36+
37+
return 0
38+
})
39+
}
40+
41+
func route53Counted(read func(c route53backend.QuotaCounter) int) quotaCounter {
42+
return counted(func(h *route53backend.Handler, _, _ string) int {
43+
if c := h.QuotaCounts(); c != nil {
44+
return read(c)
45+
}
46+
47+
return 0
48+
})
49+
}
50+
51+
type ec2QuotaCounter interface{ QuotaCount(code string) (int, bool) }
52+
53+
func ec2Counted(code string) quotaCounter {
54+
return counted(func(h *ec2backend.Handler, _, region string) int {
55+
if c, ok := h.BackendFor(region).(ec2QuotaCounter); ok {
56+
n, _ := c.QuotaCount(code)
57+
58+
return n
59+
}
60+
61+
return 0
62+
})
63+
}
64+
65+
func serviceQuotaCounters() map[string]quotaCounter {
66+
return map[string]quotaCounter{
67+
"logs/L-C7B9AAAB": counted(func(h *cwlogsbackend.Handler, _, rgn string) int { return h.LogGroupCount(rgn) }),
68+
69+
"kms/L-C2F1777E": counted(func(h *kmsbackend.Handler, _, rgn string) int { return h.KeyCount(rgn) }),
70+
"kms/L-340F62FB": counted(func(h *kmsbackend.Handler, _, rgn string) int { return h.MaxAliasesPerKey(rgn) }),
71+
"kms/L-D594A657": counted(func(h *kmsbackend.Handler, _, rgn string) int { return h.MaxGrantsPerKey(rgn) }),
72+
73+
"events/L-244521F2": eventsCounted(
74+
func(c ebbackend.QuotaCounter, rgn string) int { return c.MaxRulesPerBus(rgn) },
75+
),
76+
"events/L-658A4FD9": eventsCounted(
77+
func(c ebbackend.QuotaCounter, rgn string) int { return c.CustomBusCount(rgn) },
78+
),
79+
"events/L-595D6D42": eventsCounted(
80+
func(c ebbackend.QuotaCounter, rgn string) int { return c.ConnectionsInRegion(rgn) },
81+
),
82+
"events/L-EAC9A2AC": eventsCounted(
83+
func(c ebbackend.QuotaCounter, rgn string) int { return c.EndpointsInRegion(rgn) },
84+
),
85+
"events/L-FB1C3A6D": eventsCounted(
86+
func(c ebbackend.QuotaCounter, rgn string) int { return c.APIDestinationsInRegion(rgn) },
87+
),
88+
89+
"states/L-B66B0F91": counted(
90+
func(h *sfnbackend.Handler, _, rgn string) int { return h.StateMachineCount(rgn) },
91+
),
92+
"states/L-A9562A73": counted(func(h *sfnbackend.Handler, _, rgn string) int { return h.ActivityCount(rgn) }),
93+
"states/L-6AFCB355": counted(
94+
func(h *sfnbackend.Handler, _, rgn string) int { return h.MaxVersionsPerStateMachine(rgn) },
95+
),
96+
"states/L-C1D5EBBB": counted(
97+
func(h *sfnbackend.Handler, _, rgn string) int { return h.MaxAliasesPerStateMachine(rgn) },
98+
),
99+
100+
"route53/L-4EA4796A": route53Counted(func(c route53backend.QuotaCounter) int { return c.HostedZoneCount() }),
101+
"route53/L-ACB674F3": route53Counted(func(c route53backend.QuotaCounter) int { return c.HealthCheckCount() }),
102+
"route53/L-A72C7724": route53Counted(func(c route53backend.QuotaCounter) int { return c.DelegationSetCount() }),
103+
"route53/L-FC688E7C": route53Counted(func(c route53backend.QuotaCounter) int { return c.TrafficPolicyCount() }),
104+
"route53/L-AD61772F": route53Counted(
105+
func(c route53backend.QuotaCounter) int { return c.CidrCollectionCount() },
106+
),
107+
"route53/L-E209CC9F": route53Counted(
108+
func(c route53backend.QuotaCounter) int { return c.MaxRecordsPerHostedZone() },
109+
),
110+
111+
"vpc/L-407747CB": ec2Counted("L-407747CB"),
112+
"vpc/L-A4707A72": ec2Counted("L-A4707A72"),
113+
"vpc/L-FE5A380F": ec2Counted("L-FE5A380F"),
114+
"vpc/L-DF5E4CA3": ec2Counted("L-DF5E4CA3"),
115+
"vpc/L-E79EC296": ec2Counted("L-E79EC296"),
116+
"vpc/L-0EA8095F": ec2Counted("L-0EA8095F"),
117+
"vpc/L-589F43AA": ec2Counted("L-589F43AA"),
118+
"vpc/L-93826ACB": ec2Counted("L-93826ACB"),
119+
"ec2/L-1216C47A": ec2Counted("L-1216C47A"),
120+
"ec2/L-DB2E81BA": ec2Counted("L-DB2E81BA"),
121+
"ec2/L-417A185B": ec2Counted("L-417A185B"),
122+
"ec2/L-74FC7D96": ec2Counted("L-74FC7D96"),
123+
"ec2/L-7295265B": ec2Counted("L-7295265B"),
124+
"ec2/L-1945791B": ec2Counted("L-1945791B"),
125+
"ec2/L-43DA4232": ec2Counted("L-43DA4232"),
126+
"ec2/L-34B43A08": ec2Counted("L-34B43A08"),
127+
"ec2/L-7212CCBC": ec2Counted("L-7212CCBC"),
128+
"ec2/L-3819A6DF": ec2Counted("L-3819A6DF"),
129+
130+
"autoscaling/L-CDE20ADC": counted(func(h *asbackend.Handler, _, rgn string) int { return h.GroupCount(rgn) }),
131+
"autoscaling/L-6B80B8FA": counted(
132+
func(h *asbackend.Handler, _, rgn string) int { return h.LaunchConfigurationCount(rgn) },
133+
),
134+
"elasticfilesystem/L-848C634D": counted(func(h *efsbackend.Handler, _, rgn string) int {
135+
return h.FileSystemCount(rgn)
136+
}),
137+
"firehose/L-14BB0BE7": counted(func(h *firehosebackend.Handler, _, rgn string) int {
138+
return h.DeliveryStreamCount(rgn)
139+
}),
140+
"cognito-identity/L-8692CE1C": counted(func(h *cognitoidentitybackend.Handler, _, rgn string) int {
141+
return h.IdentityPoolCount(rgn)
142+
}),
143+
"cognito-idp/L-66E6DF30": counted(func(h *cognitoidpbackend.Handler, _, rgn string) int {
144+
return h.UserPoolCount(rgn)
145+
}),
146+
147+
"ecr/L-CFEB8E8D": counted(func(h *ecrbackend.Handler, _, rgn string) int { return h.RepositoryCount(rgn) }),
148+
}
149+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package app
2+
3+
import (
4+
_ "embed" // quota classification table
5+
"encoding/json/v2"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
11+
"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
12+
servicequotasbackend "github.com/blackbirdworks/gopherstack/services/servicequotas"
13+
)
14+
15+
//go:embed testdata/service_quota_classes.json
16+
var quotaClassesJSON []byte
17+
18+
// quotaClassEntry classifies the catalogued quotas of one service:
19+
// c counted (has a live counter), e count-of-resources without a counter (Reason says why),
20+
// s per-resource size or length limit, r rate or concurrency, o not derivable in an emulator.
21+
type quotaClassEntry struct {
22+
Quotas map[string]string `json:"quotas"`
23+
Reason string `json:"reason"`
24+
}
25+
26+
func loadQuotaClasses(t *testing.T) map[string]quotaClassEntry {
27+
t.Helper()
28+
29+
var classes map[string]quotaClassEntry
30+
require.NoError(t, json.Unmarshal(quotaClassesJSON, &classes, jsonx.V1()))
31+
32+
return classes
33+
}
34+
35+
func catalogQuotaKeys(t *testing.T) map[string]bool {
36+
t.Helper()
37+
38+
b := servicequotasbackend.NewInMemoryBackend(quotaTestAccount, quotaTestRegion)
39+
keys := map[string]bool{}
40+
token := ""
41+
42+
for {
43+
pg, err := b.ListServices(token, nil)
44+
require.NoError(t, err)
45+
46+
for _, svc := range pg.Data {
47+
for _, q := range svc.Quotas {
48+
keys[svc.Code+"/"+q.Code] = true
49+
}
50+
}
51+
52+
if pg.Next == "" {
53+
return keys
54+
}
55+
56+
token = pg.Next
57+
}
58+
}
59+
60+
func TestQuotaClassificationCoversCatalog(t *testing.T) {
61+
t.Parallel()
62+
63+
classes := loadQuotaClasses(t)
64+
catalog := catalogQuotaKeys(t)
65+
classified := map[string]string{}
66+
67+
for svc, entry := range classes {
68+
hasExempt := false
69+
70+
for code, class := range entry.Quotas {
71+
require.Contains(t, []string{"c", "e", "s", "r", "o"}, class, "%s/%s", svc, code)
72+
classified[svc+"/"+code] = class
73+
hasExempt = hasExempt || class == "e"
74+
}
75+
76+
if hasExempt {
77+
assert.NotEmpty(t, entry.Reason, "%s has count quotas without a counter and no reason", svc)
78+
}
79+
}
80+
81+
for k := range catalog {
82+
assert.Contains(
83+
t,
84+
classified,
85+
k,
86+
"catalogued quota %s is not classified: add it to testdata/service_quota_classes.json as c (and wire a counter in "+
87+
"service_quota_counters.go), e (count, no counter yet), s (size or length) or r (rate or concurrency)",
88+
k,
89+
)
90+
}
91+
92+
for k := range classified {
93+
assert.True(t, catalog[k], "classified quota %s is not catalogued", k)
94+
}
95+
}
96+
97+
func TestQuotaCountersMatchClassification(t *testing.T) {
98+
t.Parallel()
99+
100+
classes := loadQuotaClasses(t)
101+
counters := map[string]bool{}
102+
103+
for k := range quotaCounters {
104+
counters[k] = true
105+
}
106+
107+
for k := range extraQuotaCounters {
108+
counters[k] = true
109+
}
110+
111+
counted := map[string]bool{}
112+
113+
for svc, entry := range classes {
114+
for code, class := range entry.Quotas {
115+
if class == "c" {
116+
counted[svc+"/"+code] = true
117+
}
118+
}
119+
}
120+
121+
for k := range counted {
122+
assert.True(t, counters[k],
123+
"%s is classified c but has no counter: add it to serviceQuotaCounters/quotaCounters or reclassify it e", k)
124+
}
125+
126+
for k := range counters {
127+
assert.True(t, counted[k], "%s has a counter but is not classified c in testdata/service_quota_classes.json", k)
128+
}
129+
}

0 commit comments

Comments
 (0)