Commit Graph

292 Commits

Author SHA1 Message Date
Sreenithi Sridharan 7ff0c56ebd Added Python Example for Flow Control (#37044)
Have added the required client, server, proto and proto generated files.
The design of the example is as follows:

1. The client sends a bulk amount of data(approx. 2 KB in each
iteration) to the server in a streaming call.
2. The server applies back-pressure by delaying reading of the requests,
which makes the client pause sending requests after around 64KB
3. The client then resumes sending requests only after the server reads
a few requests and clears the buffer.

By adding print statements on data send/receive on both client and
server side, the client pausing/resuming requests can be seen clearly.
The client and server logs can be seen below:

**Client Logs**
```
Request 10: Sent 20000 bytes in total
Request 20: Sent 40000 bytes in total
Request 30: Sent 60000 bytes in total
Request 40: Sent 80000 bytes in total
Received 10 responses

Request 50: Sent 100000 bytes in total
Received 20 responses

Request 60: Sent 120000 bytes in total
Received 30 responses

Request 70: Sent 140000 bytes in total
Received 40 responses

Request 80: Sent 160000 bytes in total
Received 50 responses

Request 90: Sent 180000 bytes in total
Received 60 responses

Request 100: Sent 200000 bytes in total
Received 70 responses

Received 80 responses

Received 90 responses

Received 100 responses
```

**Server Logs**
```
Server started, listening on 50051
Request 10: Received 20000 bytes in total
Request 10: Sent 20000 bytes in total

Request 20: Received 40000 bytes in total
Request 20: Sent 40000 bytes in total

Request 30: Received 60000 bytes in total
Request 30: Sent 60000 bytes in total

Request 40: Received 80000 bytes in total
Request 40: Sent 80000 bytes in total

Request 50: Received 100000 bytes in total
Request 50: Sent 100000 bytes in total

Request 60: Received 120000 bytes in total
Request 60: Sent 120000 bytes in total

Request 70: Received 140000 bytes in total
Request 70: Sent 140000 bytes in total

Request 80: Received 160000 bytes in total
Request 80: Sent 160000 bytes in total

Request 90: Received 180000 bytes in total
Request 90: Sent 180000 bytes in total

Request 100: Received 200000 bytes in total
Request 100: Sent 200000 bytes in total
```
2024-07-02 21:49:39 -07:00
Eugene Ostroukhov c92b43388c [Dep] Revert "Upgrading Protobuf to v27.0 (#36753)" (#37125)
This reverts commit 0ffab55534.

Closes #37125

PiperOrigin-RevId: 648750887
2024-07-02 09:57:14 -07:00
Esun Kim 0ffab55534 [Dep] Upgrading Protobuf to v27.0 (#36753)
Closes #36753

PiperOrigin-RevId: 647792433
2024-06-28 14:09:18 -07:00
Xuan Wang 4df07a77f0 [Python o11] Add boundaries to CSM example (#36898)
* Latency in 50 percentile:
![Screenshot 2024-06-12 at 11 04
08 AM](https://github.com/grpc/grpc/assets/24593237/cb315d47-0983-40b7-ab9d-75afb93b232c)

<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
2024-06-17 12:37:15 -07:00
Xuan Wang 4f3fba65fb [Python CSM] Add example for CSM O11Y (#36829)
Verified that when following User Guide, we're able to collect metrics
and export to GCP.
Images are available at:
*
`us-docker.pkg.dev/grpc-testing/examples/csm-o11y-example-python-client:latest`
*
`us-docker.pkg.dev/grpc-testing/examples/csm-o11y-example-python-server:latest`
<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
2024-06-07 11:20:23 -07:00
Xuan Wang 811bb258d8 [Python Otel] Use registered method at server side (#36371)
Add registered method change to sync stack server.

## Note
* We're keeping both generic and registered handler in generated stubs (`*_pb2_grpc.py`) because registered method flow is not implemented in aysncio yet, since the stub is used for both sync and asyncio, we can't remove generic method flow until we fully implement the registered method flow in asyncio.

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #36371

PiperOrigin-RevId: 629842051
2024-05-01 14:43:15 -07:00
Xuan Wang 79e42f9837 [Python Otel] Remove opentelemetry version pin (#36448)
<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #36448

PiperOrigin-RevId: 629113962
2024-04-29 10:40:27 -07:00
Xuan Wang 24be69b9bd [Python O11y] Change public interface (#36094)
Address comments from design review meeting, mainly:
* Use `OpenTelemetryPlugin` as public API.
* Use keyword args to build plugin.
<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #36094

PiperOrigin-RevId: 615807264
2024-03-14 09:37:19 -07:00
Xuan Wang c910004328 [Python Stub] Add version check to stubs generated by grpcio_tools (#35906)
The stubs generated by grpcio_tools should always be used with [the same or higher version of grpcio](https://github.com/grpc/grpc/blob/master/tools/distrib/python/grpcio_tools/setup.py#L313), this change will add a run time check for this requirement inside the generated stubs and therefor enforce this requirement.

Please note for now we're just printing a warning for incorrect usage, we'll **change it to an error** soon.

Example warning message:
```
/usr/local/google/home/xuanwn/workspace/misc/grpc/examples/python/helloworld/helloworld_pb2_grpc.py:21: RuntimeWarning: The grpc package installed is at version 1.60.1, but the generated code in helloworld_pb2_grpc.py depends on grpcio>=1.63.0.dev0. Please upgrade your grpc module to grpcio>=1.63.0.dev0 or downgrade your generated code using grpcio-tools<=1.60.1. This warning will become an error in 1.64.0, scheduled for release on May 14,2024.
```
<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #35906

PiperOrigin-RevId: 615659471
2024-03-13 22:47:01 -07:00
Xuan Wang 672d8abdca [Python Otel] Allow start observability without context manager (#35932)
Allow start observability globally with a new API `start_open_telemetry_observability`.

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #35932

PiperOrigin-RevId: 612639020
2024-03-04 17:08:15 -08:00
Xuan Wang 2c9b599e5e [Python O11Y] Reapply registered method change (#35850)
This reverts commit a18279db2e.

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #35850

PiperOrigin-RevId: 607476066
2024-02-15 15:36:27 -08:00
Xuan Wang 9aa3c5835a [Python O11y] Remove exporter from public API and refactor tests (#35792)
<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #35792

PiperOrigin-RevId: 604695910
2024-02-06 10:48:40 -08:00
Xuan Wang 80f3a90556 [Python O11Y] Add observability example (#35637)
<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
2024-01-25 10:04:06 -08:00
Xuan Wang a18279db2e [Python O11Y] Revert registered method change (#35522)
We're having some issues internally, rolling this change back for now and wait for the affected users to figure out a solution.

This reverts: https://github.com/grpc/grpc/pull/35002, https://github.com/grpc/grpc/pull/35482 and https://github.com/grpc/grpc/commit/6872a7a47355128fe2c4ec17ed85f37cf9bdc848

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #35522

PiperOrigin-RevId: 597671989
2024-01-11 15:40:10 -08:00
Xuan Wang cd68c5e783 [Python Example] Add token based authentication example (#35477)
Add token based authentication example

<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
2024-01-10 11:06:46 -08:00
Xuan Wang 9a7c0b5f57 [Python Observability] Allow create call with registered method (#35002)
Based on [OpenTelemetry Metrics gRFC](https://github.com/grpc/proposal/blob/master/A66-otel-stats.md#opentelemetry-metrics), we should recored unregistered RPC method name as `other`, this PR adds the ability to pass register method information when creating a call.

We'll consider calls created using generated stubs as registered, note that this won't prevent user from setting `registered_method=True` when creating calls manually.

This is also enabled for simple stub flow but **NOT enabled for AsyncIO**, we'll add that later when start working on AsyncIO Observability.
<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #35002

PiperOrigin-RevId: 596719121
2024-01-08 15:30:17 -08:00
Xuan Wang 49d48c94ab [Python Example] Fix compression example (#34745)
Fix: https://github.com/grpc/grpc/issues/34690

Also added generated proto files to example folder so we can run example
directly.
<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
2023-10-20 09:10:14 -07:00
Xuan Wang cedef1b7f3 [Python example] Add example for TLS (#34116)
Add example for TLS.

<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
2023-08-22 13:02:40 -07:00
Sergii Tkachenko de6ed9ba9f [Python] Migrate from yapf to black (#33138)
- Switched  from yapf to black
- Reconfigure isort for black
- Resolve black/pylint idiosyncrasies 

Note: I used `--experimental-string-processing` because black was
producing "implicit string concatenation", similar to what described
here: https://github.com/psf/black/issues/1837. While currently this
feature is experimental, it will be enabled by default:
https://github.com/psf/black/issues/2188. After running black with the
new string processing so that the generated code merges these `"hello" "
world"` strings concatenations, then I removed
`--experimental-string-processing` for stability, and regenerated the
code again.

To the reviewer: don't even try to open "Files Changed" tab 😄 It's
better to review commit-by-commit, and ignore `run black and isort`.
2023-06-09 15:08:55 -07:00
molto 1980841257 [example] Fix bad example (#32161)
Channel object has no method ``stop``, it supposed to be ``close`` here.

---------

Co-authored-by: Xuan Wang <xuanwn@google.com>
2023-05-10 17:36:04 -07:00
Xuan Wang 40f20c0f48 [Python fix-it][Aysnc Example] Adding examples for aysnc interceptor context propagaton (#32840)
### Description

Fix https://github.com/grpc/grpc/issues/24470.

Adding one example which demonstrate the following use cases:

* Generate RPC ID on client side and propagate to server.
* Context propagation from client to server.
* Context propagation between different server interceptors and the
server handler.

## Use:

1. Start server: `python3 -m async_greeter_server_with_interceptor`
2. Start client: `python3 -m async_greeter_client`

### Expected Logs:

* On client side:

```
Sending request with rpc id: 73bb98beff10c2dd7b9f2252a1e2039e
Greeter client received: Hello, you!
```

* On server side:

```
INFO:root:Starting server on [::]:50051
INFO:root:Interceptor1 called with rpc_id: default
INFO:root:Interceptor2 called with rpc_id: Interceptor1-default
INFO:root:Handle rpc with id Interceptor2-Interceptor1-73bb98beff10c2dd7b9f2252a1e2039e in server handler.
```
2023-05-04 19:31:01 +00:00
Xuan Wang a190831789 Add examples for timeout, kepp_alive, reflection and health_checking (#32243)
* Add timeout example

* Add pb2 file to example

* Remove .proto file

* Add keep_alive example

* Add refelction client

* fixes

* Add example for health_check

* Changes based on comments

* Fix pylint
2023-02-03 14:11:27 -08:00
Richard Belleville d175c79935 Add lb policy example (#32256)
* Add lb policy example

* Update copyright

* This is Python 3

* Fix isort
2023-02-03 09:58:50 -08:00
Xuan Wang 10e5b2115e Add wait_for_ready with client timeout example (#32183)
* Add wait_for_ready with client timeout example

* Use with to create channel

* Fix sanity tests

* Changes based on comments

* Change thread to daemon thread

* Changes based on comments
2023-01-25 11:02:13 -08:00
Ian Rodney cfd3395e9b explain that keys must be lower cased (#31586) 2023-01-10 16:42:29 -08:00
Ho Ngok Chao 28e49b0f6f Add concurrency into python example in route_guide (#31724)
* Add concurrency into python example in route_guide

- replace await single tasks sequentially with await task_group

* Add comments for asyncio.gather for concurrency

* Correct typo

* Update asyncio_route_guide to meet google style

Co-authored-by: Richard Belleville <rbellevi@google.com>
2022-12-21 11:17:14 -08:00
niquepolice 3714762731 Fix typo in multiprocessing example Readme (#30132) 2022-11-22 14:32:56 -08:00
Xuan Wang 149f5615ba Remove enum and future (#31381)
* [Python][Remove enum34] Remove enum34

* [Python][Remove futures] Remove futures

* Remove empty deps from .bazel files
2022-10-18 14:58:30 -07:00
Xuan Wang 7aca6d4007 [Remove Six] Remove dependency on six (#31340)
* [Python][Remove Six] Remove Six from requirements
2022-10-17 09:34:45 -07:00
AmosWang 166824205e Print info when server starts (#30964) 2022-09-14 15:54:01 -07:00
Yash Tibrewal 41ec08c69a Update third_party/protobuf to 3.21.4 (#30377)
* Update third_party/protobuf

* run tools/distrib/python/make_grpcio_tools.py

* regenerate protos for ruby, php

* update build_handwritten.yaml

* regenerate projects

* Build - Use :well_known_type_protos instead of :well_known_protos

* Fix target

* Update upb

* Update Python for Protobuf 4.21 (#140)

* Update protobuf dependency on grpcio-tools

* Off by one

* Drop python 3.6 support

* Try upgrading pip

* And in the other script

* Try to figure out if we're compatible with abi3

* See what we've already got installed

* Update the requirements.txt file I didn't know existed

* And here too

* See what's installed

* Let's try that again

* Remove

* Try to confirm version

* Let me see the generated code

* Fix non-Bazel test runner

* Work for all test directories

* Regenerate example protos

* Clean up

* Generate .pyi files

* Fix type checking and linting

* Exclude pyi files from isort

* Upgrade to 3.21.4

* Update iwyu to get around messy protobuf IWYU rules

Co-authored-by: Richard Belleville <gnossen@gmail.com>
2022-08-04 09:39:49 -07:00
Lidi Zheng 3f2b3460a4 [Python] Add an UDS example (#29592) 2022-05-09 17:08:54 -07:00
Xiao ad3f591af3 [Aio] Fix typo in async graceful shutdown example (#29521)
Background: https://github.com/grpc/grpc/pull/26622
2022-05-03 10:51:44 -07:00
Michael Mercier b784a4307d Add python async example for hellostreamingworld using generator (#27343)
* Add python async example for hellostreamingworld using generator

* add stub.read() client example + fix Copyrights + small improvements

* Format and lint + remove exernal generator

* Apply lint and auto-format
2022-01-06 10:15:40 -08:00
Richard Belleville 468768865b Make Buildifier Sanity Test Strict (#27807)
* Fix all lint errors in repo.

* Use strict buildifier by default

* Whoops. That file does not exist

* Attempt fix to buildifier invocation

* Add missing copyright
2021-11-03 14:57:04 -07:00
Richard Belleville ffc43e05d8 Switch Python xDS Example Server to Listen on IPV4 Only (#27679) (#27758)
* Switch to IPV4

* Update to all hosts
2021-10-18 09:36:08 -07:00
Craig Tiller d1e01ac139 Add a test for a (now-illegal) build file construct (#27602)
* Add a test for a (now-illegal) build file construct

* add to test suite!

* fix

* fix

* fix syntax
2021-10-06 07:43:59 -07:00
小么小儿郎EL 435d5207ab fix: use == instead of is when comparing with a certain types of literals (#26519) 2021-09-21 15:36:26 -07:00
Richard Belleville a48067c4c8 Replace StopIteration with return (#26861) 2021-08-03 11:08:31 -07:00
Lidi Zheng 6c6463e1cd Add retry example for gRPC Python (#26829)
* Add retry example for gRPC Python

* Make sanity test happy && simplfy proto definition

* Fix a grammer issue
2021-07-29 17:31:05 -07:00
Lidi Zheng 2231c2ba77 Introduce Python import sorting to our sanity test suite (#26768)
* Add isort_code.sh to sanity tests

* Run tools/distrib/isort_code.sh

* Fine tune the import order for relative imports

* Make pylint and project generation happy

* Fix a few corner cases

* Use --check instead of --diff

* The import order impacts test result somehow

* Make isort print diff and check output at the same time

* Let tools/run_tests/python_utils be firstparty library

* Run isort against latest HEAD
2021-07-26 12:31:21 -07:00
Lidi Zheng 933b10d2a8 Add a correct graceful shutdwon example for the asyncio API (#26622) 2021-07-08 10:58:58 -07:00
Richard Belleville 7125bbe5a5 Add Python PSM security example (#26170)
* Add Python PSM security example

* Fix lint

* Add in maintenance port configuration

* Align CLI flags with Java

* Pylint
2021-05-05 15:57:38 -07:00
Yash Tibrewal f4e55b85bc Replace disrespectful term 2021-02-08 15:29:53 -08:00
Sergii Tkachenko 8db79e2e71 Python style: reformat code using updated yapf 0.30.0 2021-01-13 14:00:12 -05:00
Lidi Zheng e6dffc6fbe Adding three more AsyncIO examples
* Channelz or Debug
* Route guide
* Wait for ready
2021-01-06 10:52:39 -08:00
Esun Kim e0ebe46ad3 Fix python examples 2020-12-23 09:23:32 -08:00
Esun Kim e7afadc255 Refactor examples BUILD files 2020-12-23 09:23:32 -08:00
Lidi Zheng c515666a73 Merge pull request #24668 from lidizheng/example-async-bidi
Add async bidi-streaming example
2020-12-21 15:15:16 -08:00
Lidi Zheng f2d06b8458 Add async bidi-streaming example 2020-12-21 14:38:39 -08:00