@voxgig/sdkgen 4.51.0 → 4.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/voxgig-sdkgen +1 -1
- package/dist/cmp/ReadmeExplanation.js +5 -2
- package/dist/cmp/ReadmeExplanation.js.map +1 -1
- package/dist/cmp/ReadmeFeatures.js +20 -6
- package/dist/cmp/ReadmeFeatures.js.map +1 -1
- package/dist/helpers/optspec.js +2 -2
- package/dist/helpers/optspec.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/model/sdkgen.aontu +1 -1
- package/package.json +1 -1
- package/project/.sdk/model/feature/audit.aontu +1 -1
- package/project/.sdk/model/feature/cache.aontu +1 -1
- package/project/.sdk/model/feature/clienttrack.aontu +1 -1
- package/project/.sdk/model/feature/cost.aontu +1 -1
- package/project/.sdk/model/feature/debug.aontu +1 -1
- package/project/.sdk/model/feature/idempotency.aontu +1 -1
- package/project/.sdk/model/feature/log.aontu +1 -1
- package/project/.sdk/model/feature/metrics.aontu +3 -1
- package/project/.sdk/model/feature/netsim.aontu +1 -1
- package/project/.sdk/model/feature/paging.aontu +4 -1
- package/project/.sdk/model/feature/proxy.aontu +1 -1
- package/project/.sdk/model/feature/ratelimit.aontu +3 -3
- package/project/.sdk/model/feature/rbac.aontu +1 -1
- package/project/.sdk/model/feature/retry.aontu +1 -1
- package/project/.sdk/model/feature/secrets.aontu +1 -1
- package/project/.sdk/model/feature/streaming.aontu +1 -1
- package/project/.sdk/model/feature/telemetry.aontu +2 -2
- package/project/.sdk/model/feature/test.aontu +1 -1
- package/project/.sdk/model/feature/timeout.aontu +1 -1
- package/project/.sdk/model/feature/validate.aontu +1 -1
- package/project/.sdk/src/cmp/c/TestClean_c.ts +12 -11
- package/project/.sdk/src/cmp/c/fragment/Entity.fragment.c +17 -10
- package/project/.sdk/src/cmp/clojure/fragment/Entity.fragment.clj +18 -1
- package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +2 -1
- package/project/.sdk/src/cmp/csharp/fragment/EntityBase.fragment.cs +30 -2
- package/project/.sdk/src/cmp/csharp/fragment/Main.fragment.cs +31 -12
- package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +2 -1
- package/project/.sdk/src/cmp/elixir/fragment/Main.fragment.ex +51 -15
- package/project/.sdk/src/cmp/elixir/fragment/Pipeline.fragment.ex +17 -0
- package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +42 -2
- package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +42 -14
- package/project/.sdk/src/cmp/java/TestClean_java.ts +9 -4
- package/project/.sdk/src/cmp/java/fragment/EntityBase.fragment.java +21 -0
- package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +13 -8
- package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +26 -2
- package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +8 -0
- package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +8 -0
- package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +8 -0
- package/project/.sdk/src/cmp/js/fragment/EntityPatchOp.fragment.js +8 -0
- package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +8 -0
- package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +8 -0
- package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +12 -5
- package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +9 -4
- package/project/.sdk/src/cmp/kotlin/fragment/EntityBase.fragment.kt +19 -0
- package/project/.sdk/src/cmp/lua/TestClean_lua.ts +2 -1
- package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +42 -5
- package/project/.sdk/src/cmp/lua/fragment/Main.fragment.lua +44 -10
- package/project/.sdk/src/cmp/lua/utility_lua.ts +2 -1
- package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +2 -1
- package/project/.sdk/src/cmp/ocaml/fragment/RunOp.fragment.ml +36 -21
- package/project/.sdk/src/cmp/perl/TestClean_perl.ts +1 -1
- package/project/.sdk/src/cmp/perl/fragment/Entity.fragment.pm +21 -0
- package/project/.sdk/src/cmp/perl/fragment/Main.fragment.pm +31 -12
- package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +33 -4
- package/project/.sdk/src/cmp/php/fragment/Main.fragment.php +13 -6
- package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +25 -2
- package/project/.sdk/src/cmp/py/fragment/Main.fragment.py +26 -12
- package/project/.sdk/src/cmp/rb/TestClean_rb.ts +1 -1
- package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +23 -2
- package/project/.sdk/src/cmp/rb/fragment/Main.fragment.rb +27 -11
- package/project/.sdk/src/cmp/rust/TestClean_rust.ts +14 -17
- package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +22 -2
- package/project/.sdk/src/cmp/scala/TestClean_scala.ts +11 -11
- package/project/.sdk/src/cmp/scala/fragment/EntityBase.fragment.scala +14 -0
- package/project/.sdk/src/cmp/swift/TestClean_swift.ts +11 -11
- package/project/.sdk/src/cmp/swift/fragment/EntityBase.fragment.swift +9 -0
- package/project/.sdk/src/cmp/swift/fragment/Main.fragment.swift +24 -10
- package/project/.sdk/src/cmp/ts/ReadmeHowto_ts.ts +13 -8
- package/project/.sdk/src/cmp/ts/fragment/EntityBase.fragment.ts +26 -2
- package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +8 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +8 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +8 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityPatchOp.fragment.ts +8 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +8 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +8 -0
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +12 -5
- package/project/.sdk/src/cmp/zig/TestClean_zig.ts +11 -11
- package/project/.sdk/src/cmp/zig/fragment/Entity.fragment.zig +17 -10
- package/project/.sdk/src/cmp/zig/fragment/Main.fragment.zig +41 -6
- package/project/.sdk/tm/c/feature/metrics.c +7 -0
- package/project/.sdk/tm/c/feature/paging.c +231 -2
- package/project/.sdk/tm/c/feature/ratelimit.c +5 -9
- package/project/.sdk/tm/c/feature/retry.c +51 -4
- package/project/.sdk/tm/c/feature/streaming.c +2 -1
- package/project/.sdk/tm/c/feature/telemetry.c +19 -18
- package/project/.sdk/tm/c/feature/test.c +78 -54
- package/project/.sdk/tm/c/tests/feature_test.c +184 -0
- package/project/.sdk/tm/c/tests/primary_utility_test.c +2 -0
- package/project/.sdk/tm/c/utility/make_options.c +80 -9
- package/project/.sdk/tm/clojure/src/sdk/core.clj +31 -11
- package/project/.sdk/tm/clojure/src/sdk/features.clj +198 -70
- package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +70 -1
- package/project/.sdk/tm/cpp/core/types.hpp +137 -68
- package/project/.sdk/tm/cpp/feature/audit.hpp +6 -1
- package/project/.sdk/tm/cpp/feature/metrics.hpp +19 -0
- package/project/.sdk/tm/cpp/feature/paging.hpp +160 -2
- package/project/.sdk/tm/cpp/feature/ratelimit.hpp +18 -14
- package/project/.sdk/tm/cpp/feature/retry.hpp +46 -5
- package/project/.sdk/tm/cpp/feature/streaming.hpp +2 -1
- package/project/.sdk/tm/cpp/feature/telemetry.hpp +17 -10
- package/project/.sdk/tm/cpp/feature/test.hpp +63 -53
- package/project/.sdk/tm/cpp/test/feature_test.cpp +137 -0
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +35 -5
- package/project/.sdk/tm/csharp/feature/AuditFeature.cs +8 -1
- package/project/.sdk/tm/csharp/feature/MetricsFeature.cs +23 -0
- package/project/.sdk/tm/csharp/feature/PagingFeature.cs +130 -3
- package/project/.sdk/tm/csharp/feature/RatelimitFeature.cs +26 -19
- package/project/.sdk/tm/csharp/feature/RetryFeature.cs +41 -7
- package/project/.sdk/tm/csharp/feature/StreamingFeature.cs +2 -1
- package/project/.sdk/tm/csharp/feature/TelemetryFeature.cs +11 -9
- package/project/.sdk/tm/csharp/feature/TestFeature.cs +55 -67
- package/project/.sdk/tm/csharp/test/FeatureTest.cs +162 -0
- package/project/.sdk/tm/csharp/utility/MakeOptions.cs +89 -12
- package/project/.sdk/tm/elixir/lib/projectname/feature/metrics.ex +13 -0
- package/project/.sdk/tm/elixir/lib/projectname/feature/paging.ex +110 -5
- package/project/.sdk/tm/elixir/lib/projectname/feature/ratelimit.ex +6 -12
- package/project/.sdk/tm/elixir/lib/projectname/feature/retry.ex +33 -9
- package/project/.sdk/tm/elixir/lib/projectname/feature/streaming.ex +2 -1
- package/project/.sdk/tm/elixir/lib/projectname/feature/telemetry.ex +7 -7
- package/project/.sdk/tm/elixir/lib/projectname/feature/test.ex +52 -48
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +59 -35
- package/project/.sdk/tm/elixir/test/feature_test.exs +137 -0
- package/project/.sdk/tm/go/feature/audit_feature.go +1 -3
- package/project/.sdk/tm/go/feature/base_feature.go +11 -0
- package/project/.sdk/tm/go/feature/metrics_feature.go +14 -0
- package/project/.sdk/tm/go/feature/paging_feature.go +108 -2
- package/project/.sdk/tm/go/feature/ratelimit_feature.go +19 -17
- package/project/.sdk/tm/go/feature/retry_feature.go +81 -9
- package/project/.sdk/tm/go/feature/streaming_feature.go +2 -1
- package/project/.sdk/tm/go/feature/telemetry_feature.go +18 -11
- package/project/.sdk/tm/go/feature/test_feature.go +65 -55
- package/project/.sdk/tm/go/test/feature_corpus_test.go +209 -28
- package/project/.sdk/tm/go/test/feature_test.go +32 -0
- package/project/.sdk/tm/go/utility/make_options.go +111 -6
- package/project/.sdk/tm/java/core/SdkClient.java +43 -14
- package/project/.sdk/tm/java/feature/AuditFeature.java +5 -1
- package/project/.sdk/tm/java/feature/MetricsFeature.java +31 -0
- package/project/.sdk/tm/java/feature/PagingFeature.java +156 -2
- package/project/.sdk/tm/java/feature/RatelimitFeature.java +15 -13
- package/project/.sdk/tm/java/feature/RetryFeature.java +33 -6
- package/project/.sdk/tm/java/feature/StreamingFeature.java +2 -1
- package/project/.sdk/tm/java/feature/TelemetryFeature.java +17 -9
- package/project/.sdk/tm/java/feature/TestFeature.java +50 -63
- package/project/.sdk/tm/java/test/FeatureCorpusTest.java +170 -17
- package/project/.sdk/tm/java/utility/MakeOptions.java +128 -14
- package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +8 -3
- package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +99 -1
- package/project/.sdk/tm/js/src/feature/ratelimit/RatelimitFeature.js +5 -9
- package/project/.sdk/tm/js/src/feature/retry/RetryFeature.js +25 -3
- package/project/.sdk/tm/js/src/feature/streaming/StreamingFeature.js +2 -1
- package/project/.sdk/tm/js/src/feature/telemetry/TelemetryFeature.js +11 -6
- package/project/.sdk/tm/js/src/feature/test/TestFeature.js +38 -1
- package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +55 -6
- package/project/.sdk/tm/js/test/feature/Corpus.test.js +95 -25
- package/project/.sdk/tm/js/test/feature.test.js +14 -1
- package/project/.sdk/tm/kotlin/core/SdkClient.kt +23 -10
- package/project/.sdk/tm/kotlin/feature/AuditFeature.kt +5 -1
- package/project/.sdk/tm/kotlin/feature/MetricsFeature.kt +22 -0
- package/project/.sdk/tm/kotlin/feature/PagingFeature.kt +125 -2
- package/project/.sdk/tm/kotlin/feature/RatelimitFeature.kt +16 -13
- package/project/.sdk/tm/kotlin/feature/RetryFeature.kt +36 -14
- package/project/.sdk/tm/kotlin/feature/StreamingFeature.kt +4 -0
- package/project/.sdk/tm/kotlin/feature/TelemetryFeature.kt +12 -10
- package/project/.sdk/tm/kotlin/feature/TestFeature.kt +45 -48
- package/project/.sdk/tm/kotlin/test/FeatureTest.kt +114 -0
- package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +83 -14
- package/project/.sdk/tm/lua/feature/debug_feature.lua +2 -3
- package/project/.sdk/tm/lua/feature/metrics_feature.lua +5 -0
- package/project/.sdk/tm/lua/feature/paging_feature.lua +143 -2
- package/project/.sdk/tm/lua/feature/ratelimit_feature.lua +5 -9
- package/project/.sdk/tm/lua/feature/retry_feature.lua +43 -5
- package/project/.sdk/tm/lua/feature/streaming_feature.lua +2 -1
- package/project/.sdk/tm/lua/feature/telemetry_feature.lua +18 -7
- package/project/.sdk/tm/lua/feature/test_feature.lua +60 -62
- package/project/.sdk/tm/lua/test/feature_test.lua +100 -3
- package/project/.sdk/tm/lua/utility/make_options.lua +55 -13
- package/project/.sdk/tm/ocaml/sdk_features.ml +286 -60
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +34 -11
- package/project/.sdk/tm/ocaml/test/t_feature.ml +72 -1
- package/project/.sdk/tm/perl/feature/debug_feature.pm +2 -2
- package/project/.sdk/tm/perl/feature/metrics_feature.pm +5 -0
- package/project/.sdk/tm/perl/feature/paging_feature.pm +139 -2
- package/project/.sdk/tm/perl/feature/ratelimit_feature.pm +5 -11
- package/project/.sdk/tm/perl/feature/retry_feature.pm +22 -4
- package/project/.sdk/tm/perl/feature/streaming_feature.pm +2 -0
- package/project/.sdk/tm/perl/feature/telemetry_feature.pm +17 -8
- package/project/.sdk/tm/perl/feature/test_feature.pm +45 -50
- package/project/.sdk/tm/perl/t/feature.t +2 -2
- package/project/.sdk/tm/perl/t/feature_corpus.t +126 -23
- package/project/.sdk/tm/perl/utility/make_options.pm +33 -10
- package/project/.sdk/tm/php/feature/MetricsFeature.php +8 -0
- package/project/.sdk/tm/php/feature/PagingFeature.php +128 -1
- package/project/.sdk/tm/php/feature/RatelimitFeature.php +5 -9
- package/project/.sdk/tm/php/feature/RetryFeature.php +27 -3
- package/project/.sdk/tm/php/feature/StreamingFeature.php +2 -1
- package/project/.sdk/tm/php/feature/TelemetryFeature.php +10 -7
- package/project/.sdk/tm/php/feature/TestFeature.php +55 -47
- package/project/.sdk/tm/php/test/FeatureCorpusTest.php +151 -16
- package/project/.sdk/tm/php/utility/MakeOptions.php +40 -13
- package/project/.sdk/tm/py/pkg/feature/metrics_feature.py +7 -0
- package/project/.sdk/tm/py/pkg/feature/paging_feature.py +86 -1
- package/project/.sdk/tm/py/pkg/feature/ratelimit_feature.py +13 -16
- package/project/.sdk/tm/py/pkg/feature/retry_feature.py +31 -6
- package/project/.sdk/tm/py/pkg/feature/streaming_feature.py +2 -1
- package/project/.sdk/tm/py/pkg/feature/telemetry_feature.py +10 -6
- package/project/.sdk/tm/py/pkg/feature/test_feature.py +56 -53
- package/project/.sdk/tm/py/pkg/utility/make_options.py +68 -20
- package/project/.sdk/tm/py/test/test_feature.py +11 -1
- package/project/.sdk/tm/py/test/test_feature_corpus.py +111 -16
- package/project/.sdk/tm/py-data/pkg/fetch.py +6 -3
- package/project/.sdk/tm/py-data/test/test_fetch.py +7 -4
- package/project/.sdk/tm/rb/feature/debug_feature.rb +2 -2
- package/project/.sdk/tm/rb/feature/metrics_feature.rb +8 -0
- package/project/.sdk/tm/rb/feature/paging_feature.rb +87 -1
- package/project/.sdk/tm/rb/feature/ratelimit_feature.rb +12 -16
- package/project/.sdk/tm/rb/feature/retry_feature.rb +19 -3
- package/project/.sdk/tm/rb/feature/streaming_feature.rb +2 -1
- package/project/.sdk/tm/rb/feature/telemetry_feature.rb +11 -6
- package/project/.sdk/tm/rb/feature/test_feature.rb +42 -49
- package/project/.sdk/tm/rb/test/feature_corpus_test.rb +108 -24
- package/project/.sdk/tm/rb/test/feature_test.rb +1 -1
- package/project/.sdk/tm/rb/utility/make_options.rb +32 -11
- package/project/.sdk/tm/rust/feature/audit.rs +2 -2
- package/project/.sdk/tm/rust/feature/metrics.rs +24 -1
- package/project/.sdk/tm/rust/feature/paging.rs +189 -3
- package/project/.sdk/tm/rust/feature/ratelimit.rs +5 -10
- package/project/.sdk/tm/rust/feature/retry.rs +59 -6
- package/project/.sdk/tm/rust/feature/streaming.rs +3 -2
- package/project/.sdk/tm/rust/feature/support.rs +4 -0
- package/project/.sdk/tm/rust/feature/telemetry.rs +22 -11
- package/project/.sdk/tm/rust/feature/test.rs +63 -57
- package/project/.sdk/tm/rust/tests/feature_test.rs +174 -0
- package/project/.sdk/tm/rust/tests/primary_utility_test.rs +1 -0
- package/project/.sdk/tm/rust/utility/make_options.rs +122 -27
- package/project/.sdk/tm/scala/core/SdkClient.scala +45 -11
- package/project/.sdk/tm/scala/feature/AuditFeature.scala +6 -1
- package/project/.sdk/tm/scala/feature/MetricsFeature.scala +31 -1
- package/project/.sdk/tm/scala/feature/PagingFeature.scala +122 -2
- package/project/.sdk/tm/scala/feature/RatelimitFeature.scala +14 -11
- package/project/.sdk/tm/scala/feature/RetryFeature.scala +29 -7
- package/project/.sdk/tm/scala/feature/StreamingFeature.scala +2 -1
- package/project/.sdk/tm/scala/feature/TelemetryFeature.scala +12 -10
- package/project/.sdk/tm/scala/feature/TestFeature.scala +44 -44
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +41 -0
- package/project/.sdk/tm/scala/utility/Make.scala +96 -13
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/AuditFeature.swift +3 -2
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/MetricsFeature.swift +20 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/PagingFeature.swift +102 -2
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/RatelimitFeature.swift +19 -13
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/RetryFeature.swift +40 -5
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/StreamingFeature.swift +2 -1
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TelemetryFeature.swift +11 -9
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TestFeature.swift +55 -49
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +51 -13
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +111 -0
- package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +5 -0
- package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +99 -1
- package/project/.sdk/tm/ts/src/feature/ratelimit/RatelimitFeature.ts +5 -9
- package/project/.sdk/tm/ts/src/feature/retry/RetryFeature.ts +25 -3
- package/project/.sdk/tm/ts/src/feature/streaming/StreamingFeature.ts +2 -1
- package/project/.sdk/tm/ts/src/feature/telemetry/TelemetryFeature.ts +11 -6
- package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +8 -7
- package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +57 -6
- package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +95 -25
- package/project/.sdk/tm/ts/test/feature.test.ts +14 -1
- package/project/.sdk/tm/zig/core/utility.zig +107 -8
- package/project/.sdk/tm/zig/feature/metrics.zig +19 -0
- package/project/.sdk/tm/zig/feature/paging.zig +172 -4
- package/project/.sdk/tm/zig/feature/ratelimit.zig +5 -11
- package/project/.sdk/tm/zig/feature/retry.zig +41 -3
- package/project/.sdk/tm/zig/feature/streaming.zig +2 -0
- package/project/.sdk/tm/zig/feature/telemetry.zig +15 -9
- package/project/.sdk/tm/zig/feature/test.zig +56 -40
- package/project/.sdk/tm/zig/test/feature_test.zig +109 -0
- package/project/.sdk/tm/zig/test/primary_utility_test.zig +2 -0
- package/project/sdkgen-package.json +1 -1
- package/src/cmp/ReadmeExplanation.ts +5 -2
- package/src/cmp/ReadmeFeatures.ts +21 -6
- package/src/helpers/optspec.ts +2 -2
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
import json
|
|
17
17
|
import os
|
|
18
18
|
import re
|
|
19
|
+
import threading
|
|
19
20
|
import time
|
|
21
|
+
from urllib.parse import parse_qsl, urlsplit
|
|
20
22
|
|
|
21
23
|
import pytest
|
|
22
24
|
|
|
@@ -48,19 +50,28 @@ def _load_corpus():
|
|
|
48
50
|
return json.loads(f.read())
|
|
49
51
|
|
|
50
52
|
|
|
51
|
-
def _scripted_fetcher(res):
|
|
53
|
+
def _scripted_fetcher(res, sent=None, at=None):
|
|
52
54
|
"""A scripted transport built from a case's `res` list.
|
|
53
55
|
|
|
54
56
|
Responses are consumed in order and the last one repeats, so a case that
|
|
55
|
-
does not care how many attempts happen need only declare one.
|
|
57
|
+
does not care how many attempts happen need only declare one. Each URL it
|
|
58
|
+
is sent is kept in `sent`, and when it arrived in `at`; a `cut` response
|
|
59
|
+
is one whose body stops before its end.
|
|
56
60
|
"""
|
|
57
61
|
state = {"n": -1}
|
|
62
|
+
lock = threading.Lock()
|
|
63
|
+
sent = [] if sent is None else sent
|
|
64
|
+
at = [] if at is None else at
|
|
58
65
|
|
|
59
66
|
def fetcher(ctx, fullurl, fetchdef):
|
|
60
|
-
|
|
67
|
+
with lock:
|
|
68
|
+
state["n"] += 1
|
|
69
|
+
n = state["n"]
|
|
70
|
+
sent.append(fullurl)
|
|
71
|
+
at.append(time.monotonic() * 1000)
|
|
61
72
|
spec = {}
|
|
62
73
|
if res:
|
|
63
|
-
i =
|
|
74
|
+
i = n
|
|
64
75
|
if i >= len(res):
|
|
65
76
|
i = len(res) - 1
|
|
66
77
|
spec = res[i] or {}
|
|
@@ -78,6 +89,17 @@ def _scripted_fetcher(res):
|
|
|
78
89
|
if spec.get("throw") is True:
|
|
79
90
|
return None, RuntimeError("scripted transport failure")
|
|
80
91
|
|
|
92
|
+
if spec.get("cut") is True:
|
|
93
|
+
raw = json.dumps(body)
|
|
94
|
+
return {
|
|
95
|
+
"status": status,
|
|
96
|
+
"statusText": "OK" if status < 400 else "ERR",
|
|
97
|
+
"headers": dict(spec.get("headers") or {}),
|
|
98
|
+
"json": (lambda: None),
|
|
99
|
+
"body": raw[:len(raw) // 2],
|
|
100
|
+
"unreadable": True,
|
|
101
|
+
}, None
|
|
102
|
+
|
|
81
103
|
return {
|
|
82
104
|
"status": status,
|
|
83
105
|
"statusText": "OK" if status < 400 else "ERR",
|
|
@@ -89,7 +111,7 @@ def _scripted_fetcher(res):
|
|
|
89
111
|
return fetcher
|
|
90
112
|
|
|
91
113
|
|
|
92
|
-
def _client(kase):
|
|
114
|
+
def _client(kase, sent=None, at=None):
|
|
93
115
|
"""Build a client the way a caller would.
|
|
94
116
|
|
|
95
117
|
ProjectNameSDK(...), not ProjectNameSDK.test(...): the `test` feature is
|
|
@@ -104,7 +126,7 @@ def _client(kase):
|
|
|
104
126
|
# would shadow it, which is why this cannot just turn the feature on.
|
|
105
127
|
opts = {
|
|
106
128
|
"test": {"active": True},
|
|
107
|
-
"utility": {"fetcher": _scripted_fetcher(kase.get("res"))},
|
|
129
|
+
"utility": {"fetcher": _scripted_fetcher(kase.get("res"), sent, at)},
|
|
108
130
|
}
|
|
109
131
|
if kase.get("feature") is not None:
|
|
110
132
|
opts["feature"] = kase["feature"]
|
|
@@ -223,9 +245,34 @@ def _usable_pair():
|
|
|
223
245
|
return None
|
|
224
246
|
|
|
225
247
|
|
|
248
|
+
def _stream(client, op, ctrl, args=None):
|
|
249
|
+
"""Read one operation through the entity's stream(); how many it yields."""
|
|
250
|
+
ent = getattr(client, op["accessor"])()
|
|
251
|
+
return sum(1 for _ in ent.stream(op["op"], dict(args or {}), {"ctrl": ctrl}))
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _check_sent(sent, expect, label):
|
|
255
|
+
"""Each request a case expects, in order: its path, and its whole query.
|
|
256
|
+
A path is compared without its leading slash, which an SDK with no base
|
|
257
|
+
omits."""
|
|
258
|
+
assert len(sent) == len(expect), \
|
|
259
|
+
"{}: {} request(s) sent, want {}: {}".format(label, len(sent), len(expect), " | ".join(sent))
|
|
260
|
+
for i, want in enumerate(expect):
|
|
261
|
+
url = urlsplit(sent[i])
|
|
262
|
+
if want.get("path") is not None:
|
|
263
|
+
assert url.path.lstrip("/") == want["path"].lstrip("/"), \
|
|
264
|
+
"{}: request {} path: got {!r}, want {!r}".format(label, i, url.path, want["path"])
|
|
265
|
+
if want.get("query") is not None:
|
|
266
|
+
query = dict(parse_qsl(url.query, keep_blank_values=True))
|
|
267
|
+
assert query == want["query"], \
|
|
268
|
+
"{}: request {} query: got {!r}, want {!r}".format(label, i, query, want["query"])
|
|
269
|
+
|
|
270
|
+
|
|
226
271
|
def _step(client, op, step, ctrl):
|
|
227
272
|
"""One step: it may wait before its call, may add request headers for
|
|
228
|
-
its call, and may pass `args` as the operation's first argument.
|
|
273
|
+
its call, and may pass `args` as the operation's first argument. A
|
|
274
|
+
`stream` step reads the operation through stream(), and `items` is how
|
|
275
|
+
many it yields."""
|
|
229
276
|
if step.get("wait") is not None:
|
|
230
277
|
time.sleep(step["wait"] / 1000.0)
|
|
231
278
|
options = client._rootctx.options
|
|
@@ -233,6 +280,12 @@ def _step(client, op, step, ctrl):
|
|
|
233
280
|
if step.get("headers") is not None:
|
|
234
281
|
options["headers"] = dict(prior or {}, **step["headers"])
|
|
235
282
|
try:
|
|
283
|
+
if step.get("stream") is True:
|
|
284
|
+
items = _stream(client, op, ctrl, step.get("args"))
|
|
285
|
+
if step.get("items") is not None:
|
|
286
|
+
assert items == step["items"], \
|
|
287
|
+
"{}: streamed {} item(s), want {}".format(op["key"], items, step["items"])
|
|
288
|
+
return items
|
|
236
289
|
return _invoke(client, op, ctrl, step.get("args"))
|
|
237
290
|
finally:
|
|
238
291
|
if step.get("headers") is not None:
|
|
@@ -242,6 +295,30 @@ def _step(client, op, step, ctrl):
|
|
|
242
295
|
options["headers"] = prior
|
|
243
296
|
|
|
244
297
|
|
|
298
|
+
def _calls(client, op, step, ctrl):
|
|
299
|
+
"""Run a step once, or with `together: N` as N overlapping calls, and
|
|
300
|
+
return each call's exception or None."""
|
|
301
|
+
errs = [None] * int(step.get("together") or 1)
|
|
302
|
+
|
|
303
|
+
def call(i):
|
|
304
|
+
try:
|
|
305
|
+
_step(client, op, step, ctrl)
|
|
306
|
+
except Exception as err:
|
|
307
|
+
errs[i] = err
|
|
308
|
+
|
|
309
|
+
threads = [threading.Thread(target=call, args=(i,)) for i in range(len(errs))]
|
|
310
|
+
for t in threads:
|
|
311
|
+
t.start()
|
|
312
|
+
for t in threads:
|
|
313
|
+
t.join()
|
|
314
|
+
return errs
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def _busiest(sent, ms):
|
|
318
|
+
"""The most requests seen in any window of `ms`."""
|
|
319
|
+
return max([len([t for t in sent if start <= t < start + ms]) for start in sent], default=0)
|
|
320
|
+
|
|
321
|
+
|
|
245
322
|
def _resolve(node, tokens):
|
|
246
323
|
"""Replace #OPn throughout a case, keys included."""
|
|
247
324
|
if isinstance(node, str):
|
|
@@ -287,6 +364,13 @@ def _subset(actual, expect, path):
|
|
|
287
364
|
_subset(got, want, "{}.{}".format(path, k))
|
|
288
365
|
return
|
|
289
366
|
|
|
367
|
+
if isinstance(expect, list):
|
|
368
|
+
assert isinstance(actual, list) and len(actual) == len(expect), \
|
|
369
|
+
"{}: want {} item(s), got {!r}".format(path, len(expect), actual)
|
|
370
|
+
for i, want in enumerate(expect):
|
|
371
|
+
_subset(actual[i], want, "{}[{}]".format(path, i))
|
|
372
|
+
return
|
|
373
|
+
|
|
290
374
|
if isinstance(expect, bool) or not isinstance(expect, (int, float)):
|
|
291
375
|
assert actual == expect, "{}: got {!r}, want {!r}".format(path, actual, expect)
|
|
292
376
|
return
|
|
@@ -426,21 +510,23 @@ class TestFeatureCorpus:
|
|
|
426
510
|
|
|
427
511
|
# Every failing case is reported, not only the first.
|
|
428
512
|
try:
|
|
429
|
-
|
|
513
|
+
sent = []
|
|
514
|
+
at = []
|
|
515
|
+
client = _client(kase, sent, at)
|
|
430
516
|
|
|
517
|
+
# A case-level ctrl is one control object every step shares.
|
|
518
|
+
shared = kase.get("ctrl")
|
|
431
519
|
for step in (kase.get("op") or []):
|
|
432
520
|
op = by_key.get(step["op"])
|
|
433
521
|
assert op is not None, "{}: no operation {}".format(label, step["op"])
|
|
434
|
-
ctrl = step.get("ctrl") or {}
|
|
522
|
+
ctrl = step.get("ctrl") or (shared if shared is not None else {})
|
|
435
523
|
wanterr = step.get("err")
|
|
436
524
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
raise
|
|
443
|
-
except Exception as err:
|
|
525
|
+
for err in _calls(client, op, step, ctrl):
|
|
526
|
+
if err is None:
|
|
527
|
+
assert wanterr is None, \
|
|
528
|
+
"{}: {} was expected to fail, and did not".format(label, step["op"])
|
|
529
|
+
continue
|
|
444
530
|
assert wanterr is not None, \
|
|
445
531
|
"{}: {} failed unexpectedly: {}".format(label, step["op"], err)
|
|
446
532
|
if isinstance(wanterr, str):
|
|
@@ -452,6 +538,15 @@ class TestFeatureCorpus:
|
|
|
452
538
|
"{}: wrong error code: got {!r} ({}), want {!r}".format(
|
|
453
539
|
label, code, err, wanterr)
|
|
454
540
|
|
|
541
|
+
pace = kase.get("pace")
|
|
542
|
+
if pace is not None:
|
|
543
|
+
most = _busiest(at, pace["ms"])
|
|
544
|
+
assert most <= pace["max"], \
|
|
545
|
+
"{}: {} requests within {} ms, want at most {}".format(
|
|
546
|
+
label, most, pace["ms"], pace["max"])
|
|
547
|
+
|
|
548
|
+
if kase.get("sent") is not None:
|
|
549
|
+
_check_sent(sent, kase["sent"], label)
|
|
455
550
|
_subset(_record(client, name), kase.get("out"), "{}: _{}".format(label, name))
|
|
456
551
|
except Exception as err:
|
|
457
552
|
msg = str(err)
|
|
@@ -163,13 +163,16 @@ def _next_ctrl(paging: dict) -> dict | None:
|
|
|
163
163
|
if cursor is not None:
|
|
164
164
|
return {"paging": {"cursor": cursor}}
|
|
165
165
|
|
|
166
|
+
# A next link (a body `next` URL or `Link: rel="next"`): the paging
|
|
167
|
+
# feature builds the next request from it.
|
|
168
|
+
nxt = paging.get("next")
|
|
169
|
+
if nxt is not None:
|
|
170
|
+
return {"paging": {"next": nxt}}
|
|
171
|
+
|
|
166
172
|
next_page = paging.get("nextPage")
|
|
167
173
|
if next_page is not None:
|
|
168
174
|
return {"paging": {"page": next_page}}
|
|
169
175
|
|
|
170
|
-
# A `Link: rel="next"` URL with no cursor/page extracted is not something
|
|
171
|
-
# we can turn into a ctrl — the SDK builds its own request URLs. Rather
|
|
172
|
-
# than guess at query parsing, stop and keep what we have.
|
|
173
176
|
return None
|
|
174
177
|
|
|
175
178
|
|
|
@@ -30,10 +30,10 @@ class FakeClient:
|
|
|
30
30
|
return rows
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
def paging(has_more=False, cursor=None, next_page=None):
|
|
33
|
+
def paging(has_more=False, cursor=None, next_page=None, next_link=None):
|
|
34
34
|
return {
|
|
35
35
|
"page": None, "totalCount": None, "nextPage": next_page,
|
|
36
|
-
"next":
|
|
36
|
+
"next": next_link, "cursor": cursor, "hasMore": has_more,
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
|
|
@@ -125,9 +125,12 @@ class TestDrain:
|
|
|
125
125
|
rows = drain(c.call, c, max_pages=3, quiet=True)
|
|
126
126
|
assert len(rows) == 3
|
|
127
127
|
|
|
128
|
+
def test_a_next_link_is_passed_on(self):
|
|
129
|
+
# The paging feature builds the next request from the link.
|
|
130
|
+
nxt = _next_ctrl(paging(has_more=True, next_link="/w?after=b3", next_page=5))
|
|
131
|
+
assert nxt == {"paging": {"next": "/w?after=b3"}}
|
|
132
|
+
|
|
128
133
|
def test_has_more_without_a_usable_token_stops(self):
|
|
129
|
-
# A Link: rel="next" URL with no cursor/page is not something we can
|
|
130
|
-
# turn into a ctrl; stopping beats guessing at query parsing.
|
|
131
134
|
c = FakeClient([([{"a": 1}], paging(has_more=True))])
|
|
132
135
|
rows = drain(c.call, c, quiet=True)
|
|
133
136
|
assert len(rows) == 1
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# timing. The SDK's own clean rules (clean.keys and every registered secret
|
|
6
6
|
# value) apply to the whole entry, and the "redact" option ADDS header names
|
|
7
7
|
# on top of them. An optional
|
|
8
|
-
# "
|
|
8
|
+
# "onEntry" callback receives each finished entry (e.g. to stream to a
|
|
9
9
|
# console). "max" caps the buffer (default 100). The clock is injectable
|
|
10
10
|
# ("now", ms) for deterministic tests.
|
|
11
11
|
|
|
@@ -113,7 +113,7 @@ class ProjectNameDebugFeature < ProjectNameBaseFeature
|
|
|
113
113
|
max = @options["max"].nil? ? 100 : @options["max"]
|
|
114
114
|
buf.shift while buf.length > max
|
|
115
115
|
|
|
116
|
-
on_entry = @options["
|
|
116
|
+
on_entry = @options["onEntry"]
|
|
117
117
|
if on_entry.is_a?(Proc)
|
|
118
118
|
begin
|
|
119
119
|
on_entry.call(entry)
|
|
@@ -74,6 +74,14 @@ class ProjectNameMetricsFeature < ProjectNameBaseFeature
|
|
|
74
74
|
|
|
75
75
|
_bump(m["total"], ok, dur)
|
|
76
76
|
_bump(op, ok, dur)
|
|
77
|
+
|
|
78
|
+
sink = @options["sink"]
|
|
79
|
+
if sink.is_a?(Proc)
|
|
80
|
+
begin
|
|
81
|
+
sink.call(ctx.utility.clean.call(ctx, m))
|
|
82
|
+
rescue StandardError
|
|
83
|
+
end
|
|
84
|
+
end
|
|
77
85
|
end
|
|
78
86
|
|
|
79
87
|
def _bump(bucket, ok, dur)
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
# priority. Parameter names ("pageParam", "limitParam", "cursorParam"),
|
|
10
10
|
# "startPage" (default 1) and page size ("limit") are configurable.
|
|
11
11
|
|
|
12
|
+
require 'uri'
|
|
12
13
|
require_relative 'base_feature'
|
|
13
14
|
|
|
14
15
|
class ProjectNamePagingFeature < ProjectNameBaseFeature
|
|
@@ -55,6 +56,8 @@ class ProjectNamePagingFeature < ProjectNameBaseFeature
|
|
|
55
56
|
|
|
56
57
|
if !paging["cursor"].nil?
|
|
57
58
|
spec.query[cursor_param] = paging["cursor"]
|
|
59
|
+
elsif paging["next"].is_a?(String) && !_foreign?(paging["next"], spec.base)
|
|
60
|
+
_follow(spec, paging["next"])
|
|
58
61
|
elsif spec.query[page_param].nil?
|
|
59
62
|
# A record written back by PreResult holds the page just fetched as
|
|
60
63
|
# "page" and the one to fetch as "nextPage", so nextPage wins.
|
|
@@ -117,6 +120,7 @@ class ProjectNamePagingFeature < ProjectNameBaseFeature
|
|
|
117
120
|
"nextPage" => _num(_header(headers, "x-next-page")),
|
|
118
121
|
"next" => nil,
|
|
119
122
|
"cursor" => nil,
|
|
123
|
+
"foreign" => nil,
|
|
120
124
|
"hasMore" => false,
|
|
121
125
|
}
|
|
122
126
|
|
|
@@ -162,7 +166,13 @@ class ProjectNamePagingFeature < ProjectNameBaseFeature
|
|
|
162
166
|
|
|
163
167
|
# Body-level signals; snake_case forms are read first so camelCase wins.
|
|
164
168
|
if body.is_a?(Hash)
|
|
165
|
-
|
|
169
|
+
unless body["next"].nil?
|
|
170
|
+
if _link?(body["next"])
|
|
171
|
+
paging["next"] = paging["next"] || body["next"]
|
|
172
|
+
else
|
|
173
|
+
paging["cursor"] = body["next"]
|
|
174
|
+
end
|
|
175
|
+
end
|
|
166
176
|
paging["cursor"] = body["next_cursor"] unless body["next_cursor"].nil?
|
|
167
177
|
paging["cursor"] = body["cursor"] unless body["cursor"].nil?
|
|
168
178
|
paging["cursor"] = body["nextCursor"] unless body["nextCursor"].nil?
|
|
@@ -180,6 +190,14 @@ class ProjectNamePagingFeature < ProjectNameBaseFeature
|
|
|
180
190
|
end
|
|
181
191
|
end
|
|
182
192
|
|
|
193
|
+
# A link to another origin is recorded, never followed, and ends the walk.
|
|
194
|
+
base = ctx.spec ? ctx.spec.base : (ctx.options || {})["base"]
|
|
195
|
+
paging["next"] = _resolve(paging["next"], ctx.spec.url) if paging["next"].is_a?(String) && ctx.spec
|
|
196
|
+
if !paging["next"].nil? && _foreign?(paging["next"], base)
|
|
197
|
+
paging["foreign"] = paging["next"]
|
|
198
|
+
paging["next"] = nil
|
|
199
|
+
end
|
|
200
|
+
|
|
183
201
|
# Cursor presence only INFERS another page. When the server stated the
|
|
184
202
|
# answer outright — relay's `hasNextPage: false`, or a body `hasMore` —
|
|
185
203
|
# that wins: a final page normally carries both an end cursor and
|
|
@@ -190,6 +208,10 @@ class ProjectNamePagingFeature < ProjectNameBaseFeature
|
|
|
190
208
|
!paging["next"].nil? || !paging["cursor"].nil? || !paging["nextPage"].nil?
|
|
191
209
|
end
|
|
192
210
|
|
|
211
|
+
if !paging["foreign"].nil? && paging["cursor"].nil? && paging["nextPage"].nil?
|
|
212
|
+
paging["hasMore"] = false
|
|
213
|
+
end
|
|
214
|
+
|
|
193
215
|
result.paging = paging
|
|
194
216
|
|
|
195
217
|
if ctx.ctrl && ctx.ctrl.respond_to?(:paging=)
|
|
@@ -206,6 +228,70 @@ class ProjectNamePagingFeature < ProjectNameBaseFeature
|
|
|
206
228
|
@client.instance_variable_set(:@_paging, { "last" => paging })
|
|
207
229
|
end
|
|
208
230
|
|
|
231
|
+
PAGING_ORIGIN = %r{\A[a-z][a-z0-9+.-]*://[^/?#]*}i
|
|
232
|
+
|
|
233
|
+
# Under the `next` option's default, a URL or an absolute path is a link and
|
|
234
|
+
# anything else a cursor; `cursor` and `url` pin the reading.
|
|
235
|
+
def _link?(nxt)
|
|
236
|
+
return false unless nxt.is_a?(String)
|
|
237
|
+
mode = @options["next"] || "auto"
|
|
238
|
+
mode == "url" ||
|
|
239
|
+
(mode != "cursor" && (PAGING_ORIGIN.match?(nxt) || nxt.start_with?("/")))
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def _origin(text)
|
|
243
|
+
m = text.is_a?(String) ? PAGING_ORIGIN.match(text) : nil
|
|
244
|
+
m ? m[0].downcase : ""
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def _foreign?(link, base)
|
|
248
|
+
origin = _origin(link)
|
|
249
|
+
origin != "" && origin != _origin(base)
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
PAGING_SCHEME = /\A[a-z][a-z0-9+.-]*:/i
|
|
253
|
+
PAGING_HOLDER = "http://placeholder.invalid"
|
|
254
|
+
|
|
255
|
+
# RFC 3986 reference resolution against the URL of the request that
|
|
256
|
+
# returned the link. A link on that URL's origin comes back as its path and
|
|
257
|
+
# query; an absolute link is left as the server wrote it.
|
|
258
|
+
def _resolve(link, url)
|
|
259
|
+
return link if !url.is_a?(String) || url.empty? || PAGING_SCHEME.match?(link)
|
|
260
|
+
from = URI(PAGING_ORIGIN.match?(url) ? url : PAGING_HOLDER + (url.start_with?("/") ? "" : "/") + url)
|
|
261
|
+
out = from.merge(link)
|
|
262
|
+
return out.to_s.sub(/#.*\z/, "") if out.scheme != from.scheme || out.authority != from.authority
|
|
263
|
+
out.path + (out.query.nil? ? "" : "?" + out.query)
|
|
264
|
+
rescue URI::Error
|
|
265
|
+
link
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
# The request goes to the link's path and query, on the SDK's own origin.
|
|
269
|
+
def _follow(spec, nxt)
|
|
270
|
+
rest = nxt.sub(PAGING_ORIGIN, "").split("#", 2)[0] || ""
|
|
271
|
+
path, rawquery = rest.split("?", 2)
|
|
272
|
+
|
|
273
|
+
query = {}
|
|
274
|
+
(rawquery || "").split("&").each do |pair|
|
|
275
|
+
next if pair.empty?
|
|
276
|
+
key, val = pair.split("=", 2)
|
|
277
|
+
query[_unescape(key)] = _unescape(val || "")
|
|
278
|
+
end
|
|
279
|
+
(spec.authquery || []).each { |key| query[key] = spec.query[key] }
|
|
280
|
+
|
|
281
|
+
origin = PAGING_ORIGIN.match(spec.base.to_s)
|
|
282
|
+
spec.base = origin ? origin[0] : ""
|
|
283
|
+
spec.prefix = ""
|
|
284
|
+
spec.path = path || ""
|
|
285
|
+
spec.suffix = ""
|
|
286
|
+
spec.query = query
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
def _unescape(text)
|
|
290
|
+
URI.decode_www_form_component(text)
|
|
291
|
+
rescue ArgumentError
|
|
292
|
+
text
|
|
293
|
+
end
|
|
294
|
+
|
|
209
295
|
def _list?(ctx)
|
|
210
296
|
ops = @options["ops"] || ["list"]
|
|
211
297
|
ops.include?(ctx.op ? ctx.op.name : nil)
|
|
@@ -20,6 +20,7 @@ class ProjectNameRatelimitFeature < ProjectNameBaseFeature
|
|
|
20
20
|
@options = {}
|
|
21
21
|
@tokens = 0
|
|
22
22
|
@last = 0
|
|
23
|
+
@lock = Mutex.new
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
def init(ctx, options)
|
|
@@ -47,24 +48,19 @@ class ProjectNameRatelimitFeature < ProjectNameBaseFeature
|
|
|
47
48
|
rate = @options["rate"] || 5
|
|
48
49
|
burst = @options["burst"].nil? ? rate : @options["burst"]
|
|
49
50
|
|
|
50
|
-
# Refill
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
@tokens
|
|
58
|
-
|
|
51
|
+
# Refill, then reserve this call's token before any wait: a negative
|
|
52
|
+
# count is the calls already queued, so overlapping calls pace in turn.
|
|
53
|
+
wait_ms = @lock.synchronize do
|
|
54
|
+
now = _now
|
|
55
|
+
elapsed = now - @last
|
|
56
|
+
@last = now
|
|
57
|
+
@tokens = [burst, @tokens + (elapsed / 1000.0) * rate].min - 1
|
|
58
|
+
next 0 if @tokens >= 0
|
|
59
|
+
ms = ((-@tokens / rate.to_f) * 1000).ceil
|
|
60
|
+
_track(ctx, ms)
|
|
61
|
+
ms
|
|
59
62
|
end
|
|
60
|
-
|
|
61
|
-
# Not enough tokens: wait for one to accrue, then consume it.
|
|
62
|
-
needed = 1 - @tokens
|
|
63
|
-
wait_ms = ((needed / rate.to_f) * 1000).ceil
|
|
64
|
-
_track(ctx, wait_ms)
|
|
65
63
|
_sleep(wait_ms)
|
|
66
|
-
@last = _now
|
|
67
|
-
@tokens = 0
|
|
68
64
|
end
|
|
69
65
|
|
|
70
66
|
def _now
|
|
@@ -70,7 +70,7 @@ class ProjectNameRetryFeature < ProjectNameBaseFeature
|
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
def _backoff(res, attempt, min_delay, max_delay, factor)
|
|
73
|
-
#
|
|
73
|
+
# A server-provided Retry-After wins over the computed backoff.
|
|
74
74
|
ra = _retry_after(res)
|
|
75
75
|
return [max_delay, ra].min unless ra.nil?
|
|
76
76
|
base = min_delay * (factor**attempt)
|
|
@@ -85,8 +85,24 @@ class ProjectNameRetryFeature < ProjectNameBaseFeature
|
|
|
85
85
|
v = nil
|
|
86
86
|
headers.each { |k, hv| v = hv if k.to_s.downcase == "retry-after" }
|
|
87
87
|
return nil if v.nil?
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
ProjectNameRetryFeature.retry_after_ms(v.to_s, (Time.now.to_f * 1000).to_i)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
MONTHS = %w[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec].freeze
|
|
92
|
+
|
|
93
|
+
IMF_FIXDATE = /\A(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d{2}) ([A-Z][a-z]{2}) (\d{4}) (\d{2}):(\d{2}):(\d{2}) GMT\z/
|
|
94
|
+
|
|
95
|
+
# RFC 9110 Retry-After: delay-seconds or an IMF-fixdate, else nil.
|
|
96
|
+
def self.retry_after_ms(value, now)
|
|
97
|
+
s = value.gsub(/\A[ \t]+|[ \t]+\z/, "")
|
|
98
|
+
return s.to_i * 1000 if s.match?(/\A[0-9]+\z/)
|
|
99
|
+
m = IMF_FIXDATE.match(s)
|
|
100
|
+
return nil if m.nil? || !MONTHS.include?(m[2])
|
|
101
|
+
day, year, hour, min, sec = [1, 3, 4, 5, 6].map { |i| m[i].to_i }
|
|
102
|
+
return nil if day < 1 || day > 31 || hour > 23 || min > 59 || sec > 60
|
|
103
|
+
at = Time.utc(year, MONTHS.index(m[2]) + 1, day, hour, min, [sec, 59].min).to_i * 1000
|
|
104
|
+
at += 1000 if sec == 60
|
|
105
|
+
[0, at - now].max
|
|
90
106
|
end
|
|
91
107
|
|
|
92
108
|
def _sleep(ms)
|
|
@@ -30,8 +30,9 @@ class ProjectNameStreamingFeature < ProjectNameBaseFeature
|
|
|
30
30
|
def PreResult(ctx)
|
|
31
31
|
return unless @active
|
|
32
32
|
return unless _streamable?(ctx)
|
|
33
|
+
# A failed result keeps no stream, so the entity's stream raises its error.
|
|
33
34
|
result = ctx.result
|
|
34
|
-
return if result.nil?
|
|
35
|
+
return if result.nil? || !result.err.nil?
|
|
35
36
|
|
|
36
37
|
feature = self
|
|
37
38
|
result.streaming = true
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
# invoked with each finished span. Trace/span id generation ("idgen") and
|
|
9
9
|
# the clock ("now", ms) are injectable for deterministic tests.
|
|
10
10
|
|
|
11
|
+
require 'securerandom'
|
|
12
|
+
|
|
11
13
|
require_relative 'base_feature'
|
|
12
14
|
|
|
13
15
|
class ProjectNameTelemetryFeature < ProjectNameBaseFeature
|
|
@@ -20,7 +22,6 @@ class ProjectNameTelemetryFeature < ProjectNameBaseFeature
|
|
|
20
22
|
@client = nil
|
|
21
23
|
@options = {}
|
|
22
24
|
@spans = {}
|
|
23
|
-
@seq = 0
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
def init(ctx, options)
|
|
@@ -28,7 +29,6 @@ class ProjectNameTelemetryFeature < ProjectNameBaseFeature
|
|
|
28
29
|
@options = options.is_a?(Hash) ? options : {}
|
|
29
30
|
@active = @options["active"] == true
|
|
30
31
|
@spans = {}
|
|
31
|
-
@seq = 0
|
|
32
32
|
|
|
33
33
|
return unless @active
|
|
34
34
|
|
|
@@ -111,10 +111,15 @@ class ProjectNameTelemetryFeature < ProjectNameBaseFeature
|
|
|
111
111
|
def _id(kind)
|
|
112
112
|
idgen = @options["idgen"]
|
|
113
113
|
return idgen.call(kind) if idgen.is_a?(Proc)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
_random_hex(kind == "trace" ? 16 : 8)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# W3C trace context: lowercase hex from the platform's random source, never all zeros.
|
|
118
|
+
def _random_hex(nbytes)
|
|
119
|
+
loop do
|
|
120
|
+
hex = SecureRandom.hex(nbytes)
|
|
121
|
+
return hex if hex.match?(/[^0]/)
|
|
122
|
+
end
|
|
118
123
|
end
|
|
119
124
|
|
|
120
125
|
def _now
|