Skip to content

Commit

Permalink
vet: add check for trailing spaces (grpc#7576)
Browse files Browse the repository at this point in the history
* vet: trailing spaces check
  • Loading branch information
purnesh42H authored Sep 12, 2024
1 parent 7fb7ac7 commit b6fde8c
Show file tree
Hide file tree
Showing 29 changed files with 145 additions and 141 deletions.
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ How to get your contributions merged smoothly and quickly.
is a great place to start. These issues are well-documented and usually can be
resolved with a single pull request.

- If you are adding a new file, make sure it has the copyright message template
at the top as a comment. You can copy over the message from an existing file
- If you are adding a new file, make sure it has the copyright message template
at the top as a comment. You can copy over the message from an existing file
and update the year.

- The grpc package should only depend on standard Go packages and a small number
Expand All @@ -41,10 +41,10 @@ How to get your contributions merged smoothly and quickly.
- Provide a good **PR description** as a record of **what** change is being made
and **why** it was made. Link to a github issue if it exists.

- If you want to fix formatting or style, consider whether your changes are an
obvious improvement or might be considered a personal preference. If a style
change is based on preference, it likely will not be accepted. If it corrects
widely agreed-upon anti-patterns, then please do create a PR and explain the
- If you want to fix formatting or style, consider whether your changes are an
obvious improvement or might be considered a personal preference. If a style
change is based on preference, it likely will not be accepted. If it corrects
widely agreed-upon anti-patterns, then please do create a PR and explain the
benefits of the change.

- Unless your PR is trivial, you should expect there will be reviewer comments
Expand Down
2 changes: 1 addition & 1 deletion Documentation/server-reflection-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ The `list` command lists services exposed at a given port:
- Describe all services

The `describe` command inspects a service given its full name (in the format
of \<package\>.\<service\>).
of \<package\>.\<service\>).

```sh
$ grpcurl -plaintext localhost:50051 describe helloworld.Greeter
Expand Down
8 changes: 4 additions & 4 deletions authz/grpc_authz_end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var authzTests = map[string]struct {
"DeniesRPCMatchInDenyNoMatchInAllow": {
authzPolicy: `{
"name": "authz",
"allow_rules":
"allow_rules":
[
{
"name": "allow_StreamingOutputCall",
Expand Down Expand Up @@ -166,11 +166,11 @@ var authzTests = map[string]struct {
"/grpc.testing.TestService/UnaryCall",
"/grpc.testing.TestService/StreamingInputCall"
],
"headers":
"headers":
[
{
"key": "key-abc",
"values":
"values":
[
"val-abc",
"val-def"
Expand Down Expand Up @@ -250,7 +250,7 @@ var authzTests = map[string]struct {
[
{
"name": "allow_StreamingOutputCall",
"request":
"request":
{
"paths":
[
Expand Down
4 changes: 2 additions & 2 deletions authz/grpc_authz_server_interceptors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func (s) TestNewStatic(t *testing.T) {
wantErr: fmt.Errorf(`"name" is not present`),
},
"ValidPolicyCreatesInterceptor": {
authzPolicy: `{
authzPolicy: `{
"name": "authz",
"allow_rules":
"allow_rules":
[
{
"name": "allow_all"
Expand Down
6 changes: 3 additions & 3 deletions cmd/protoc-gen-go-grpc/protoc-gen-go-grpc_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.

# Uncomment to enable debugging.
# set -x
# set -x

WORKDIR="$(dirname $0)"
TEMPDIR=$(mktemp -d)
Expand All @@ -24,7 +24,7 @@ trap "rm -rf ${TEMPDIR}" EXIT

# Build protoc-gen-go-grpc binary and add to $PATH.
pushd "${WORKDIR}"
go build -o "${TEMPDIR}" .
go build -o "${TEMPDIR}" .
PATH="${TEMPDIR}:${PATH}"
popd

Expand All @@ -38,7 +38,7 @@ GENFILE="${TEMPDIR}/examples/route_guide/routeguide/route_guide_grpc.pb.go"

# diff is piped to [[ $? == 1 ]] to avoid exiting on diff but exit on error
# (like if the file was not found). See man diff for more info.
DIFF=$(diff "${GOLDENFILE}" "${GENFILE}" || [[ $? == 1 ]])
DIFF=$(diff "${GOLDENFILE}" "${GENFILE}" || [[ $? == 1 ]])
if [[ -n "${DIFF}" ]]; then
echo -e "ERROR: Generated file differs from golden file:\n${DIFF}"
echo -e "If you have made recent changes to protoc-gen-go-grpc," \
Expand Down
2 changes: 1 addition & 1 deletion examples/features/advancedtls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The clients are designed to call these servers with varying configurations of cr
```
# Run the server
$ go run server/main.go -credentials_directory $(pwd)/creds
# Run the clients from the `grpc-go/examples/features/advancedtls` directory
# Run the clients from the `grpc-go/examples/features/advancedtls` directory
$ go run client/main.go -credentials_directory $(pwd)/creds
```

Expand Down
10 changes: 5 additions & 5 deletions examples/features/advancedtls/creds/client_cert.pem
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ Certificate:
6e:bb:bb
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Key Identifier:
X509v3 Subject Key Identifier:
DE:03:BD:A3:0E:63:F4:97:C2:52:70:63:E8:BE:A9:DF:F1:9A:7B:56
X509v3 Authority Key Identifier:
X509v3 Authority Key Identifier:
50:76:C3:5C:6B:12:E1:92:0F:28:F8:F2:43:A6:80:C2:9C:E8:56:D6
X509v3 Basic Constraints:
X509v3 Basic Constraints:
CA:FALSE
X509v3 Key Usage:
X509v3 Key Usage:
Digital Signature, Key Encipherment
X509v3 Subject Alternative Name:
X509v3 Subject Alternative Name:
DNS:localhost, IP Address:0.0.0.0
Signature Algorithm: sha256WithRSAEncryption
Signature Value:
Expand Down
10 changes: 5 additions & 5 deletions examples/features/advancedtls/creds/client_cert_revoked.pem
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ Certificate:
6e:bb:bb
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Key Identifier:
X509v3 Subject Key Identifier:
DE:03:BD:A3:0E:63:F4:97:C2:52:70:63:E8:BE:A9:DF:F1:9A:7B:56
X509v3 Authority Key Identifier:
X509v3 Authority Key Identifier:
50:76:C3:5C:6B:12:E1:92:0F:28:F8:F2:43:A6:80:C2:9C:E8:56:D6
X509v3 Basic Constraints:
X509v3 Basic Constraints:
CA:FALSE
X509v3 Key Usage:
X509v3 Key Usage:
Digital Signature, Key Encipherment
X509v3 Subject Alternative Name:
X509v3 Subject Alternative Name:
DNS:localhost, IP Address:0.0.0.0
Signature Algorithm: sha256WithRSAEncryption
Signature Value:
Expand Down
10 changes: 5 additions & 5 deletions examples/features/advancedtls/creds/server_cert.pem
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ Certificate:
03:71:c1
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Key Identifier:
X509v3 Subject Key Identifier:
4C:57:E2:72:97:CF:DC:C4:B8:4E:DB:D4:C1:C6:3D:AE:EF:D7:0A:19
X509v3 Authority Key Identifier:
X509v3 Authority Key Identifier:
50:76:C3:5C:6B:12:E1:92:0F:28:F8:F2:43:A6:80:C2:9C:E8:56:D6
X509v3 Basic Constraints:
X509v3 Basic Constraints:
CA:FALSE
X509v3 Key Usage:
X509v3 Key Usage:
Digital Signature, Key Encipherment
X509v3 Subject Alternative Name:
X509v3 Subject Alternative Name:
DNS:localhost, IP Address:0.0.0.0
Signature Algorithm: sha256WithRSAEncryption
Signature Value:
Expand Down
10 changes: 5 additions & 5 deletions examples/features/advancedtls/creds/server_cert_revoked.pem
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ Certificate:
03:71:c1
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Key Identifier:
X509v3 Subject Key Identifier:
4C:57:E2:72:97:CF:DC:C4:B8:4E:DB:D4:C1:C6:3D:AE:EF:D7:0A:19
X509v3 Authority Key Identifier:
X509v3 Authority Key Identifier:
50:76:C3:5C:6B:12:E1:92:0F:28:F8:F2:43:A6:80:C2:9C:E8:56:D6
X509v3 Basic Constraints:
X509v3 Basic Constraints:
CA:FALSE
X509v3 Key Usage:
X509v3 Key Usage:
Digital Signature, Key Encipherment
X509v3 Subject Alternative Name:
X509v3 Subject Alternative Name:
DNS:localhost, IP Address:0.0.0.0
Signature Algorithm: sha256WithRSAEncryption
Signature Value:
Expand Down
8 changes: 4 additions & 4 deletions examples/features/debugging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
Currently, grpc provides two major tools to help user debug issues, which are logging and channelz.

## Logs
gRPC has put substantial logging instruments on critical paths of gRPC to help users debug issues.
gRPC has put substantial logging instruments on critical paths of gRPC to help users debug issues.
The [Log Levels](https://github.com/grpc/grpc-go/blob/master/Documentation/log_levels.md) doc describes
what each log level means in the gRPC context.

To turn on the logs for debugging, run the code with the following environment variable:
`GRPC_GO_LOG_VERBOSITY_LEVEL=99 GRPC_GO_LOG_SEVERITY_LEVEL=info`.
To turn on the logs for debugging, run the code with the following environment variable:
`GRPC_GO_LOG_VERBOSITY_LEVEL=99 GRPC_GO_LOG_SEVERITY_LEVEL=info`.

## Channelz
We also provide a runtime debugging tool, Channelz, to help users with live debugging.
Expand All @@ -17,7 +17,7 @@ See the channelz blog post here ([link](https://grpc.io/blog/a-short-introductio
details about how to use channelz service to debug live program.

## Try it
The example is able to showcase how logging and channelz can help with debugging. See the channelz
The example is able to showcase how logging and channelz can help with debugging. See the channelz
blog post linked above for full explanation.

```
Expand Down
16 changes: 8 additions & 8 deletions examples/features/encryption/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ create grpc
base on TLS. Refer to the
[godoc](https://godoc.org/google.golang.org/grpc/credentials) for details.

In our example, we use the public/private keys created ahead:
* "server_cert.pem" contains the server certificate (public key).
* "server_key.pem" contains the server private key.
In our example, we use the public/private keys created ahead:
* "server_cert.pem" contains the server certificate (public key).
* "server_key.pem" contains the server private key.
* "ca_cert.pem" contains the certificate (certificate authority)
that can verify the server's certificate.

Expand All @@ -56,7 +56,7 @@ And finally we make an RPC call over the created `grpc.ClientConn` to test the s
connection based upon TLS is successfully up.

### ALTS
NOTE: ALTS currently needs special early access permission on GCP. You can ask
NOTE: ALTS currently needs special early access permission on GCP. You can ask
about the detailed process in https://groups.google.com/forum/#!forum/grpc-io.

ALTS is the Google's Application Layer Transport Security, which supports mutual
Expand Down Expand Up @@ -93,12 +93,12 @@ allows users to configure mutual TLS at the connection level.

In this example, we use the following public/private keys created ahead of time:

* "server_cert.pem" contains the server's certificate (public key).
* "server_key.pem" contains the server's private key.
* "server_cert.pem" contains the server's certificate (public key).
* "server_key.pem" contains the server's private key.
* "ca_cert.pem" contains the certificate of the certificate authority that can
verify the server's certificate.
* "client_cert.pem" contains the client's certificate (public key).
* "client_key.pem" contains the client's private key.
* "client_cert.pem" contains the client's certificate (public key).
* "client_key.pem" contains the client's private key.
* "client_ca_cert.pem" contains the certificate of the certificate authority
that can verify the client's certificate.

Expand Down
6 changes: 3 additions & 3 deletions examples/features/health/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
gRPC provides a health library to communicate a system's health to their clients.
It works by providing a service definition via the [health/v1](https://github.com/grpc/grpc-proto/blob/master/grpc/health/v1/health.proto) api.

By using the health library, clients can gracefully avoid using servers as they encounter issues.
By using the health library, clients can gracefully avoid using servers as they encounter issues.
Most languages provide an implementation out of box, making it interoperable between systems.

## Try it
Expand All @@ -30,7 +30,7 @@ This configuration indicates which backend `serviceName` should be inspected whe
An empty string (`""`) typically indicates the overall health of a server should be reported.

```go
// import grpc/health to enable transparent client side checking
// import grpc/health to enable transparent client side checking
import _ "google.golang.org/grpc/health"

// set up appropriate service config
Expand Down Expand Up @@ -59,6 +59,6 @@ This state is often seen at the start up of a server instance.
Conversely, `NOT_SERVING` indicates the system is unable to service requests at the time.

`SERVICE_UNKNOWN` communicates the `serviceName` requested by the client is not known by the server.
This status is only reported by the `Watch()` call.
This status is only reported by the `Watch()` call.

A server may toggle its health using `healthServer.SetServingStatus("serviceName", servingStatus)`.
2 changes: 1 addition & 1 deletion examples/features/metadata_interceptor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *wrappedStream) Context() context.Context {
}

func SomeStreamInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
// Get the incoming metadata from the RPC context, and add a new
// Get the incoming metadata from the RPC context, and add a new
// key-value pair to it.
md, ok := metadata.FromIncomingContext(ctx)
md.Append("key1", "value1")
Expand Down
52 changes: 26 additions & 26 deletions examples/features/stats_monitoring/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Stats Monitoring Handler

This example demonstrates the use of the [`stats`](https://pkg.go.dev/google.golang.org/grpc/stats) package for reporting various
network and RPC stats.
_Note that all fields are READ-ONLY and the APIs of the `stats` package are
This example demonstrates the use of the [`stats`](https://pkg.go.dev/google.golang.org/grpc/stats) package for reporting various
network and RPC stats.
_Note that all fields are READ-ONLY and the APIs of the `stats` package are
experimental_.

## Try it
Expand All @@ -17,42 +17,42 @@ go run client/main.go

## Explanation

gRPC provides a mechanism to hook on to various events (phases) of the
request-response network cycle through the [`stats.Handler`](https://pkg.go.dev/google.golang.org/grpc/stats#Handler) interface. To access
these events, a concrete type that implements `stats.Handler` should be passed to
`grpc.WithStatsHandler()` on the client side and `grpc.StatsHandler()` on the
gRPC provides a mechanism to hook on to various events (phases) of the
request-response network cycle through the [`stats.Handler`](https://pkg.go.dev/google.golang.org/grpc/stats#Handler) interface. To access
these events, a concrete type that implements `stats.Handler` should be passed to
`grpc.WithStatsHandler()` on the client side and `grpc.StatsHandler()` on the
server side.

The `HandleRPC(context.Context, RPCStats)` method on `stats.Handler` is called
multiple times during a request-response cycle, and various event stats are
passed to its `RPCStats` parameter (an interface). The concrete types that
implement this interface are: `*stats.Begin`, `*stats.InHeader`, `*stats.InPayload`,
`*stats.InTrailer`, `*stats.OutHeader`, `*stats.OutPayload`, `*stats.OutTrailer`, and
The `HandleRPC(context.Context, RPCStats)` method on `stats.Handler` is called
multiple times during a request-response cycle, and various event stats are
passed to its `RPCStats` parameter (an interface). The concrete types that
implement this interface are: `*stats.Begin`, `*stats.InHeader`, `*stats.InPayload`,
`*stats.InTrailer`, `*stats.OutHeader`, `*stats.OutPayload`, `*stats.OutTrailer`, and
`*stats.End`. The order of these events differs on client and server.

Similarly, the `HandleConn(context.Context, ConnStats)` method on `stats.Handler`
is called twice, once at the beginning of the connection with `*stats.ConnBegin`
Similarly, the `HandleConn(context.Context, ConnStats)` method on `stats.Handler`
is called twice, once at the beginning of the connection with `*stats.ConnBegin`
and once at the end with `*stats.ConnEnd`.

The [`stats.Handler`](https://pkg.go.dev/google.golang.org/grpc/stats#Handler) interface also provides
`TagRPC(context.Context, *RPCTagInfo) context.Context` and
`TagConn(context.Context, *ConnTagInfo) context.Context` methods. These methods
The [`stats.Handler`](https://pkg.go.dev/google.golang.org/grpc/stats#Handler) interface also provides
`TagRPC(context.Context, *RPCTagInfo) context.Context` and
`TagConn(context.Context, *ConnTagInfo) context.Context` methods. These methods
are mainly used to attach network related information to the given context.

The `TagRPC(context.Context, *RPCTagInfo) context.Context` method returns a
context from which the context used for the rest lifetime of the RPC will be
The `TagRPC(context.Context, *RPCTagInfo) context.Context` method returns a
context from which the context used for the rest lifetime of the RPC will be
derived. This behavior is consistent between the gRPC client and server.

The context returned from
The context returned from
`TagConn(context.Context, *ConnTagInfo) context.Context` has varied lifespan:

- In the gRPC client:
The context used for the rest lifetime of the RPC will NOT be derived from
this context. Hence the information attached to this context can only be
- In the gRPC client:
The context used for the rest lifetime of the RPC will NOT be derived from
this context. Hence the information attached to this context can only be
consumed by `HandleConn(context.Context, ConnStats)` method.
- In the gRPC server:
The context used for the rest lifetime of the RPC will be derived from
- In the gRPC server:
The context used for the rest lifetime of the RPC will be derived from
this context.

NOTE: The [stats](https://pkg.go.dev/google.golang.org/grpc/stats) package should only be used for network monitoring purposes,
NOTE: The [stats](https://pkg.go.dev/google.golang.org/grpc/stats) package should only be used for network monitoring purposes,
and not as an alternative to [interceptors](https://github.com/grpc/grpc-go/blob/master/examples/features/interceptor).
3 changes: 3 additions & 0 deletions scripts/vet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ not git grep "\"github.com/golang/protobuf/*" -- "*.go" ':(exclude)reflection/te
# - Ensure all usages of grpc_testing package are renamed when importing.
not git grep "\(import \|^\s*\)\"google.golang.org/grpc/interop/grpc_testing" -- "*.go"

# - Ensure that no trailing spaces are found.
not git grep '[[:blank:]]$'

# - Ensure all xds proto imports are renamed to *pb or *grpc.
git grep '"github.com/envoyproxy/go-control-plane/envoy' -- '*.go' ':(exclude)*.pb.go' | not grep -v 'pb "\|grpc "'

Expand Down
Loading

0 comments on commit b6fde8c

Please sign in to comment.