-
Notifications
You must be signed in to change notification settings - Fork 618
feat: support bi-directional eventstream over H2 #1082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AllanZhengYP
merged 16 commits into
aws:master
from
AllanZhengYP:h2-eventstream-continue
May 27, 2020
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8f3469a
feat: revive h2 eventstream dependencies
AllanZhengYP f1117bb
feat: support generating eventstream signing customizations
AllanZhengYP 6fea336
chore: address PR feedback
AllanZhengYP 506dd5e
chore: update yarn.lock
AllanZhengYP df055d8
fix: move runtime agnostic eventstream serde into standalone package
AllanZhengYP da10db9
feat: replace es signing mw with es mw and payload handler to handle …
AllanZhengYP 408858f
feat: handle unmodeled exceptions in eventstream serde
AllanZhengYP 89bf523
fix: move eventstream handler after signing step
AllanZhengYP e36426c
chore: add codegen for eventstream handler
AllanZhengYP 3961f6f
test(eventstream-handler-node): add unit tests
AllanZhengYP 877a301
chore(eventstream-handler-node): add docs
AllanZhengYP 77e5db2
feat: manually update transcribe client
AllanZhengYP 3c128cd
test(client-transcribe-streaming): add integration test
AllanZhengYP 930cdc6
chore: add integration test script to project root
AllanZhengYP 877f309
chore: address PR feedbacks
AllanZhengYP 5e49dcc
chore: remove h2 request handler codegen for Kinesis
AllanZhengYP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ package-lock.json | |
|
||
*.d.ts | ||
*.js | ||
!jest*.config.js | ||
*.js.map |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/coverage/ | ||
/docs/ | ||
/test/ | ||
tsconfig.test.json | ||
*.tsbuildinfo | ||
jest.config.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const base = require("../../jest.config.base.js"); | ||
|
||
module.exports = { | ||
...base, | ||
// Only test cjs dist, avoid testing the package twice | ||
testPathIgnorePatterns: ["/node_modules/", "/es/", ".*.integ.spec.js"], | ||
coveragePathIgnorePatterns: [ | ||
"/node_modules/", | ||
"/commands/", | ||
"/protocols/", // protocols tested in protocol protocol_tests folder | ||
"endpoints" // endpoint tested in tests/functional/endpoints | ||
] | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const base = require("../../jest.config.base.js"); | ||
|
||
module.exports = { | ||
...base, | ||
testMatch: ["**/*.integ.spec.js"] | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
clients/client-transcribe-streaming/test/index.integ.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { TranscribeStreaming } from "../index"; | ||
import { createReadStream } from "fs"; | ||
import { join } from "path"; | ||
const audio = createReadStream(join(__dirname, "speech.wav")); | ||
|
||
describe("TranscribeStream client", () => { | ||
const client = new TranscribeStreaming({}); | ||
afterAll(() => { | ||
client.destroy(); | ||
}); | ||
|
||
it("should stream the transcript", async () => { | ||
const LanguageCode = "en-US"; | ||
const MediaEncoding = "pcm"; | ||
const MediaSampleRateHertz = 44100; | ||
const result = await client.startStreamTranscription({ | ||
LanguageCode, | ||
MediaEncoding, | ||
MediaSampleRateHertz, | ||
AudioStream: (async function* () { | ||
for await (const chunk of audio) { | ||
yield { AudioEvent: { AudioChunk: chunk } }; | ||
} | ||
})() | ||
}); | ||
expect(result.LanguageCode).toBe(LanguageCode); | ||
expect(result.MediaEncoding).toBe(MediaEncoding); | ||
expect(result.MediaSampleRateHertz).toBe(MediaSampleRateHertz); | ||
expect(result.TranscriptResultStream).toBeDefined(); | ||
const transcripts = []; | ||
for await (const event of result.TranscriptResultStream!) { | ||
transcripts.push(event); | ||
} | ||
expect( | ||
transcripts.filter(event => event["TranscriptEvent"]).length | ||
).toBeGreaterThan(0); | ||
}, 60000); | ||
}); |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,6 @@ | |
"es2015.symbol.wellknown" | ||
], | ||
"outDir": "dist/es" | ||
} | ||
}, | ||
"exclude": ["test"] | ||
} |
133 changes: 133 additions & 0 deletions
133
.../java/software/amazon/smithy/aws/typescript/codegen/AddEventStreamHandlingDependency.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package software.amazon.smithy.aws.typescript.codegen; | ||
|
||
import static software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention.HAS_CONFIG; | ||
import static software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention.HAS_MIDDLEWARE; | ||
|
||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Consumer; | ||
|
||
import software.amazon.smithy.codegen.core.SymbolProvider; | ||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.knowledge.EventStreamIndex; | ||
import software.amazon.smithy.model.knowledge.TopDownIndex; | ||
import software.amazon.smithy.model.shapes.OperationShape; | ||
import software.amazon.smithy.model.shapes.ServiceShape; | ||
import software.amazon.smithy.typescript.codegen.LanguageTarget; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptDependency; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptSettings; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptWriter; | ||
import software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin; | ||
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration; | ||
import software.amazon.smithy.utils.ListUtils; | ||
import software.amazon.smithy.utils.MapUtils; | ||
|
||
/** | ||
* Adds runtime client plugins that handle the eventstream flow in request, | ||
* including eventstream payload signing. | ||
*/ | ||
public class AddEventStreamHandlingDependency implements TypeScriptIntegration { | ||
@Override | ||
public List<RuntimeClientPlugin> getClientPlugins() { | ||
return ListUtils.of( | ||
RuntimeClientPlugin.builder() | ||
.withConventions(AwsDependency.MIDDLEWARE_EVENTSTREAM.dependency, | ||
"EventStream", HAS_CONFIG) | ||
.servicePredicate(AddEventStreamHandlingDependency::hasEventStreamInput) | ||
.build(), | ||
RuntimeClientPlugin.builder() | ||
.withConventions(AwsDependency.MIDDLEWARE_EVENTSTREAM.dependency, | ||
"EventStream", HAS_MIDDLEWARE) | ||
.operationPredicate(AddEventStreamHandlingDependency::hasEventStreamInput) | ||
.build() | ||
); | ||
} | ||
|
||
@Override | ||
public void addConfigInterfaceFields( | ||
TypeScriptSettings settings, | ||
Model model, | ||
SymbolProvider symbolProvider, | ||
TypeScriptWriter writer | ||
) { | ||
if (hasEventStreamInput(model, settings.getService(model))) { | ||
writer.addImport("EventStreamPayloadHandlerProvider", "__EventStreamPayloadHandlerProvider", | ||
TypeScriptDependency.AWS_SDK_TYPES.packageName); | ||
writer.writeDocs("The function that provides necessary utilities for handling request event stream."); | ||
writer.write("eventStreamPayloadHandlerProvider?: __EventStreamPayloadHandlerProvider;\n"); | ||
} | ||
} | ||
|
||
@Override | ||
public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters( | ||
TypeScriptSettings settings, | ||
Model model, | ||
SymbolProvider symbolProvider, | ||
LanguageTarget target | ||
) { | ||
ServiceShape service = settings.getService(model); | ||
if (!hasEventStreamInput(model, service)) { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
switch (target) { | ||
case NODE: | ||
return MapUtils.of("eventStreamPayloadHandlerProvider", writer -> { | ||
writer.addDependency(AwsDependency.AWS_SDK_EVENTSTREAM_HANDLER_NODE); | ||
writer.addImport("eventStreamPayloadHandlerProvider", "eventStreamPayloadHandlerProvider", | ||
AwsDependency.AWS_SDK_EVENTSTREAM_HANDLER_NODE.packageName); | ||
writer.write("eventStreamPayloadHandlerProvider,"); | ||
}); | ||
case BROWSER: | ||
/** | ||
* Browser doesn't support streaming requests as of March 2020. | ||
* Each service client needs to support eventstream request in browser individually. | ||
* Services like TranscribeStreaming support it via WebSocket. | ||
*/ | ||
return MapUtils.of("eventStreamPayloadHandlerProvider", writer -> { | ||
writer.addDependency(TypeScriptDependency.INVALID_DEPENDENCY); | ||
writer.addImport("invalidFunction", "invalidFunction", | ||
TypeScriptDependency.INVALID_DEPENDENCY.packageName); | ||
writer.openBlock("eventStreamPayloadHandlerProvider: () => ({", "}),", () -> { | ||
writer.write("handle: invalidFunction(\"event stream request is not supported in browser.\"),"); | ||
}); | ||
}); | ||
case REACT_NATIVE: | ||
/** | ||
* ReactNative doesn't support streaming requests as of March 2020. | ||
* Here we don't supply invalidFunction. Each service client needs to support eventstream request | ||
* in RN has to implement a customization providing its own eventStreamSignerProvider | ||
*/ | ||
return MapUtils.of("eventStreamPayloadHandlerProvider", writer -> { | ||
writer.addDependency(TypeScriptDependency.INVALID_DEPENDENCY); | ||
writer.addImport("invalidFunction", "invalidFunction", | ||
TypeScriptDependency.INVALID_DEPENDENCY.packageName); | ||
writer.openBlock("eventStreamPayloadHandlerProvider: () => ({", "}),", () -> { | ||
writer.write("handle: invalidFunction(\"event stream request is not supported in ReactNative.\"),"); | ||
}); | ||
}); | ||
default: | ||
return Collections.emptyMap(); | ||
} | ||
} | ||
|
||
private static boolean hasEventStreamInput(Model model, ServiceShape service) { | ||
TopDownIndex topDownIndex = model.getKnowledge(TopDownIndex.class); | ||
Set<OperationShape> operations = topDownIndex.getContainedOperations(service); | ||
EventStreamIndex eventStreamIndex = model.getKnowledge(EventStreamIndex.class); | ||
for (OperationShape operation : operations) { | ||
if (eventStreamIndex.getInputInfo(operation).isPresent()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private static boolean hasEventStreamInput(Model model, ServiceShape service, OperationShape operation) { | ||
EventStreamIndex eventStreamIndex = model.getKnowledge(EventStreamIndex.class); | ||
return eventStreamIndex.getInputInfo(operation).isPresent(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.