Skip to content

Conversation

@alicejli
Copy link
Contributor

@alicejli alicejli commented Jan 14, 2022

As part of supporting dynamic routing annotations per google/api/routing.proto, this adds the following:

  1. Several sample routing annotations to the Echo.Echo method
  2. The ability for each Echo service to echo the contents set with the x-goog-request-params metadata key to the response headers

An example of how to set and read the headers in Go:

func main() {
	conn, err := grpc.Dial("localhost:7469", grpc.WithInsecure())
	// This is what the generated client library should be creating
        md := metadata.New(map[string]string{"x-goog-request-params": "testHeader"})
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()
	opt := option.WithGRPCConn(conn)
	ctx := metadata.NewOutgoingContext(context.Background(), md)

	echo, err := showcase.NewEchoClient(ctx, opt)
	if err != nil {
		log.Fatal(err)
	}
	defer echo.Close()

	content := "HELLO WORLD"

	req := &showcasepb.EchoRequest{
		Response: &showcasepb.EchoRequest_Content{
			Content: content,
		},
	}
	// Very important step! Another metadata instance must be provided to the `grpc.Header()` with which to capture them.
	mdForHeaders := metadata.New(map[string]string{})

	resp, err := echo.Echo(ctx, req, gax.WithGRPCOptions(grpc.Header(&mdForHeaders)))

	fmt.Printf("This is the response %v\nThis is the header:%v", resp, mdForHeaders.Get("x-goog-request-params")

	if err != nil {
		log.Fatal(err)
	}
}

The result should be:

This is the response content:"HELLO WORLD"
This is the header:[testHeader]

Each language microgenerator can use the following sample tests to the Echo method to confirm the dynamic routing annotations are being generated properly.

  1. EchoRequest without header or other_header field specified
    Header should be empty.

EchoRequest{
   other_header: “waldo”
}

Expected Header: baz=waldo

EchoRequest{
   header: “foo”
}

Expected Header: routing_id=foo&header=foo

EchoRequest{
   header: “projects/foo”
}

Expected Header: routing_id=projects/foo&header=projects/foo

EchoRequest{
   header: “projects/foo/instances/quuz/rows”
}

Expected Header: instance_id=instances/quuz&table_name=projects/foo/instances/quuz/rows&header&super_id=projects/foo&routing_id=projects/foo/instances/quuz/rows&header=projects/foo/instances/quuz/rows

EchoRequest{
   header: “regions/foo/zones/bar/rows””
}

Expected Header: table_name=regions/foo/zones/bar/rows&routing_id=regions/foo/zones/bar/rows&header=regions/foo/zones/bar/rows

EchoRequest{
   header: “projects/foo/instances/bar”
}

Expected Header: super_id=projects/foo&routing_id=projects/foo/instances/bar&header=projects/foo/instances/bar

EchoRequest{
   header: “thud"
   other_header: “projects/foo/instances/bar”
}

Expected Header: quz=projects/foo&baz=projects/foo/instances/bar&routing_id=thud&header=thud

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Jan 14, 2022
@alicejli alicejli marked this pull request as ready for review January 14, 2022 03:18
@alicejli alicejli requested a review from a team as a code owner January 14, 2022 03:18
@alicejli alicejli changed the title feat: add ability to echo headers as well as sample routing annotations feat: add ability to echo headers & sample routing annotations on echo method Jan 14, 2022
Copy link
Collaborator

@noahdietz noahdietz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

Copy link
Collaborator

@noahdietz noahdietz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with this. I will let you, @alicejli decide if you want eyes from the other reviewers.

renovate-bot and others added 2 commits January 24, 2022 17:53
…apis#973)

[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/google/go-cmp](https://github.com/google/go-cmp) | require | patch | `v0.5.6` -> `v0.5.7` |

---

### Release Notes

<details>
<summary>google/go-cmp</summary>

### [`v0.5.7`](https://github.com/google/go-cmp/releases/v0.5.7)

[Compare Source](https://github.com/google/go-cmp/compare/v0.5.6...v0.5.7)

Reporter changes:

-   ([#&#8203;266](https://github.com/google/go-cmp/issues/266)) Fix textual printing of byte slices
-   ([#&#8203;275](https://github.com/google/go-cmp/issues/275)) Reduce minimum length for specialize string diffing
-   ([#&#8203;276](https://github.com/google/go-cmp/issues/276)) Use any alias instead of interface{}

Code cleanup changes:

-   ([#&#8203;281](https://github.com/google/go-cmp/issues/281)) Update minimum supported version to go1.11
-   ([#&#8203;282](https://github.com/google/go-cmp/issues/282)) Drop hacks to work around Go reflection bugs in Go1.9
-   ([#&#8203;285](https://github.com/google/go-cmp/issues/285)) Add //go:build lines
-   ([#&#8203;262](https://github.com/google/go-cmp/issues/262)) Fix staticcheck findings
-   ([#&#8203;263](https://github.com/google/go-cmp/issues/263)) Avoid shadowing variable
-   ([#&#8203;268](https://github.com/google/go-cmp/issues/268)) Use sha256 in test
-   ([#&#8203;271](https://github.com/google/go-cmp/issues/271)) Fix spelling mistakes
-   ([#&#8203;269](https://github.com/google/go-cmp/issues/269)) Change build status badge

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/gapic-showcase).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants