Skip to content

Commit 2f74826

Browse files
committed
Improve documentation and code comments
1 parent 1062cbb commit 2f74826

20 files changed

Lines changed: 74 additions & 76 deletions

README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@
55
[![GoReportCard](https://goreportcard.com/badge/github.com/nexcode/rpcplatform)](https://goreportcard.com/report/github.com/nexcode/rpcplatform)
66
[![CodeCov](https://codecov.io/gh/nexcode/rpcplatform/graph/badge.svg)](https://codecov.io/gh/nexcode/rpcplatform)
77

8-
An `easy-to-use` platform for creating microservices without complex infrastructure solutions.
9-
Only [etcd](https://etcd.io) required. Out of the box you get a service discovery, tracing between
10-
services and other useful things. [gRPC](https://grpc.io) is used for communication between services.
8+
An `easy-to-use` platform for creating microservices without complex infrastructure dependencies.
9+
Only [etcd](https://etcd.io) is required. Out of the box you get service discovery, tracing between
10+
services and other useful features. [gRPC](https://grpc.io) is used for communication between services.
1111

12-
## etcd required
12+
## etcd is required
1313

14-
If there is no etcd in your infrastructure, you can install it from a
15-
[docker container](https://etcd.io/docs/v3.6/op-guide/container/) for tests:
14+
If there is no etcd in your infrastructure, you can run it via
15+
[Docker](https://etcd.io/docs/v3.6/op-guide/container/) for testing:
1616

1717
```shell
1818
docker run -d --name etcd \
1919
-p 2379:2379 -p 2380:2380 \
20-
gcr.io/etcd-development/etcd:v3.6.5 /usr/local/bin/etcd \
21-
--name etcd --initial-cluster etcd=http://127.0.0.1:2380 \
22-
--initial-advertise-peer-urls http://127.0.0.1:2380 --listen-peer-urls http://0.0.0.0:2380 \
23-
--advertise-client-urls http://127.0.0.1:2379 --listen-client-urls http://0.0.0.0:2379
20+
-e ETCD_NAME=etcd -e ETCD_INITIAL_CLUSTER=etcd=http://127.0.0.1:2380 \
21+
-e ETCD_INITIAL_ADVERTISE_PEER_URLS=http://127.0.0.1:2380 -e ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380 \
22+
-e ETCD_ADVERTISE_CLIENT_URLS=http://127.0.0.1:2379 -e ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379 \
23+
gcr.io/etcd-development/etcd:v3.6.5
2424
```
2525

26-
Of course, you can use docker in production or install etcd using your favorite package manager.
26+
Of course, you can use Docker in production or install etcd using your favorite package manager.
2727
Just remember that the example above is for testing purposes!
2828

2929
## How does it work?
3030

31-
All you need to do is give your server a name. When it starts, it will automatically select a free port and run on it (unless you specify otherwise).
32-
All clients will connect to this server by its name. If there are multiple servers with the same name, load balancing will be performed between them.
31+
All you need to do is assign a name to your server. When it starts, it will automatically select a free port and listen on it (unless you specify otherwise).
32+
All clients will connect to this server by its name. If there are multiple servers with the same name, load balancing is distributed among them.
3333

34-
> In the following code examples, error handling will be removed to improve readability. A pre-built [proto](examples/quickstart/proto) will also be used.
34+
> In the following code examples, error handling is omitted to improve readability. A pre-built [proto](examples/quickstart/proto) will also be used.
3535
3636
First, let's create a new `rpcplatform` instance:
3737

@@ -41,24 +41,24 @@ rpcp, err := rpcplatform.New("rpcplatform", etcdClient,
4141
rpcplatform.ClientOptions.GRPCOptions(grpc.WithTransportCredentials(insecure.NewCredentials())),
4242
),
4343
)
44-
````
44+
```
4545

46-
Now let's create a new server named `myServerName`, give it the implementation of our `Sum` service and run it on the localhost (`sumServer` implementation will be omitted):
46+
Now let's create a new server named `myServerName`, register the implementation of our `Sum` service and run it on localhost (`sumServer` implementation is omitted):
4747

4848
```go
4949
server, err := rpcp.NewServer("myServerName", "localhost:")
5050
proto.RegisterSumServer(server.Server(), &sumServer{})
5151
err = server.Serve()
52-
````
52+
```
5353

54-
And finally, we create a client that connects to our `myServerName` (`sumClient` usage will be omitted):
54+
And finally, we create a client that connects to our `myServerName` (`sumClient` usage is omitted):
5555

5656
```go
5757
client, err := rpcp.NewClient("myServerName")
5858
sumClient := proto.NewSumClient(client.Client())
59-
````
59+
```
6060

61-
This is already enough for everything to work, we can add or remove copies of our server and add new clients — everything will work!
61+
This setup is fully functional: you can add or remove copies of your server and create new clients dynamically.
6262
But to see our **service graph** and get **telemetry for all gRPC methods**, we need to run containers with telemetry services and enable telemetry in `rpcplatform`.
6363

6464
Let's run containers with Zipkin and Jaeger:
@@ -68,7 +68,7 @@ docker run -d --name zipkin -p 9411:9411 openzipkin/zipkin
6868
docker run -d --name jaeger -p 16686:16686 -p 4317:4317 jaegertracing/all-in-one
6969
```
7070

71-
Now let's create the necessary collectors and add `OpenTelemetry` option to the `rpcplatform` instance:
71+
Now let's create the necessary collectors and add the `OpenTelemetry` option to the `rpcplatform` instance:
7272

7373
```go
7474
otlpExporter, err := otlptracegrpc.New(context.Background(),
@@ -83,9 +83,9 @@ rpcp, err := rpcplatform.New("rpcplatform", etcdClient,
8383
),
8484
rpcplatform.PlatformOptions.OpenTelemetry("myServiceName", 1, otlpExporter, zipkinExporter),
8585
)
86-
````
86+
```
8787

88-
The tracing system's web interface is available in a browser:
88+
The tracing dashboards are available at:
8989

9090
| Zipkin (`http://localhost:9411`) | Jaeger (`http://localhost:16686`) |
9191
| :------------------------------------------: | :------------------------------------------: |
@@ -94,5 +94,5 @@ The tracing system's web interface is available in a browser:
9494
## Usage examples (with source code)
9595

9696
- [QuickStart](examples/quickstart): contains the simplest example without additional features
97-
- [OpenTelemetry](examples/opentelemetry): example with connecting distributed tracing systems
97+
- [OpenTelemetry](examples/opentelemetry): example integrating distributed tracing systems
9898
- [Attributes](examples/attributes): example using additional settings for client and server

attributes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
"github.com/nexcode/rpcplatform/internal/attributes"
2121
)
2222

23-
// NewAttributes returns attributes with default values.
23+
// NewAttributes returns new Attributes with default values.
2424
func NewAttributes() *Attributes {
2525
return attributes.New()
2626
}
2727

28-
// Attributes provides server attribute values.
28+
// Attributes contains server attribute values.
2929
type Attributes = attributes.Attributes

client_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"google.golang.org/grpc"
2121
)
2222

23-
// Client return the original gRPC ClientConn object.
23+
// Client returns the underlying gRPC ClientConn.
2424
func (c *Client) Client() *grpc.ClientConn {
2525
return c.client
2626
}

client_id.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package rpcplatform
1818

19-
// ID return the client identifier.
19+
// ID returns the client identifier.
2020
func (c *Client) ID() string {
2121
return c.id
2222
}

examples/attributes/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Adding attributes
22

3-
This example is very similar to [QuickStart](../quickstart), but now we will use additional attributes for the server and will receive them on every update in the channel.
3+
This example is similar to the [QuickStart](../quickstart) example, but it uses additional server attributes that are sent with every channel update.
44

55
## Launching this demo
66

@@ -19,6 +19,6 @@ cd examples/opentelemetry/client
1919
go run .
2020
```
2121

22-
## Additional comments
22+
## Additional notes
2323

24-
Currently there are two servers and one client running. If you launch another server, then one of the three servers will become a backup server, and the client will continue to interact with only two servers. If we want active servers to be selected using priority, we can use the `BalancerPriority` option for server attributes. Each server receives requests based on its weight, so by changing the value of `BalancerWeight` attribute we will distribute load the way we need.
24+
Currently, two servers and one client are running. If another server is launched, one becomes a backup server, and the client continues interacting with only two servers. To select active servers by priority, use the `BalancerPriority` server attribute. Each server receives requests based on its weight, so changing the `BalancerWeight` attribute value distributes load as needed.

examples/opentelemetry/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
## Tracing systems preparation
1+
## Tracing system preparation
22

3-
In this example, we will connect two distributed tracing systems such as [Zipkin](https://zipkin.io) and [Jaeger](https://www.jaegertracing.io).
4-
You can run some of these systems or even use something else. List of supported [exporters](https://pkg.go.dev/go.opentelemetry.io/otel/exporters).
3+
In this example, we will connect two distributed tracing systems: [Zipkin](https://zipkin.io) and [Jaeger](https://www.jaegertracing.io).
4+
You can run these systems or use other alternatives. See the list of supported [exporters](https://pkg.go.dev/go.opentelemetry.io/otel/exporters).
55

6-
For the test, let's run two docker containers with tracing systems:
6+
For testing, let's run two Docker containers with the tracing systems:
77

88
```shell
99
docker run -d --name zipkin -p 9411:9411 openzipkin/zipkin
1010
docker run -d --name jaeger -p 16686:16686 -p 4317:4317 jaegertracing/all-in-one
1111
```
1212

13-
## Launching this demo
13+
## Launching the demo
1414

1515
```shell
1616
cd examples/opentelemetry/server
@@ -22,7 +22,7 @@ cd examples/opentelemetry/client
2222
go run .
2323
```
2424

25-
## Let's see the tracing reports
25+
## Viewing tracing reports
2626

2727
- Open Zipkin UI in a browser: `http://localhost:9411`
2828
- Open Jaeger UI in a browser: `http://localhost:16686`

examples/quickstart/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Introduction to gRPC usage
22

3-
This example contains an already compiled [proto](proto) package.
3+
This example contains a pre-compiled [proto](proto) package.
44
Detailed instructions for rebuilding (if needed) are [attached](proto/README.md).
55

66
## Launching this demo
@@ -20,11 +20,11 @@ cd examples/quickstart/client
2020
go run .
2121
```
2222

23-
Now two servers and one client are running!
23+
You should now have two servers and one client running!
2424

25-
## It works?
25+
## Does it work?
2626

27-
Your console will have the corresponding logs:
27+
You will see the corresponding logs in your console:
2828

2929
```shell
3030
request: 4 + 9
@@ -41,5 +41,5 @@ request: 3 + 0
4141
1 + 3 = 4
4242
```
4343

44-
You can start new servers, stop running ones and add or remove clients...
45-
Everything will work!
44+
You can start additional servers, stop existing ones, and add or remove clients.
45+
The system will continue to function correctly!

internal/options/client.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,16 @@ import (
2424
type Client struct{}
2525

2626
// MaxActiveServers sets the maximum number of active servers the client will connect to.
27-
// If there are more servers than this value, no requests will be made to them.
27+
// Servers exceeding this limit will not receive requests.
2828
func (Client) MaxActiveServers(count int) func(*config.Client) {
2929
return func(c *config.Client) {
3030
c.MaxActiveServers = count
3131
}
3232
}
3333

34-
// GRPCOptions provide []grpc.DialOption to the client.
34+
// GRPCOptions adds gRPC dial options to the client.
3535
func (Client) GRPCOptions(options ...grpc.DialOption) func(*config.Client) {
3636
return func(c *config.Client) {
3737
c.GRPCOptions = append(c.GRPCOptions, options...)
3838
}
3939
}
40-
41-
// var Client ClientOption = client{}
42-
43-
// type ClientOption interface {
44-
// MaxActiveServers(count int) func(*config.Client)
45-
// GRPCOptions(options ...grpc.DialOption) func(*config.Client)
46-
// }

internal/options/platform.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,23 @@ import (
2323

2424
type Platform struct{}
2525

26-
// ClientOptions sets global settings for new clients that can be overwritten by local settings for each client.
26+
// ClientOptions sets default options for all new clients.
27+
// Local client options can override these global settings.
2728
func (Platform) ClientOptions(options ...func(*config.Client)) func(*config.Platform) {
2829
return func(c *config.Platform) {
2930
c.ClientOptions = append(c.ClientOptions, options...)
3031
}
3132
}
3233

33-
// ServerOptions sets global settings for new servers that can be overwritten by local settings for each server.
34+
// ServerOptions sets default options for all new servers.
35+
// Local server options can override these global settings.
3436
func (Platform) ServerOptions(options ...func(*config.Server)) func(*config.Platform) {
3537
return func(c *config.Platform) {
3638
c.ServerOptions = append(c.ServerOptions, options...)
3739
}
3840
}
3941

40-
// OpenTelemetry configures OpenTelemetry settings for clients and servers.
42+
// OpenTelemetry configures OpenTelemetry tracing for clients and servers.
4143
func (Platform) OpenTelemetry(serviceName string, sampleRate float64, exporters ...trace.SpanExporter) func(*config.Platform) {
4244
return func(c *config.Platform) {
4345
c.OpenTelemetry = &config.OpenTelemetry{

internal/options/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ import (
2424

2525
type Server struct{}
2626

27-
// PublicAddr is used when the server is not accessible to clients at the address it is located at.
27+
// PublicAddr sets the public address for the server when it is not accessible to clients at its listening address.
2828
func (Server) PublicAddr(publicAddr string) func(*config.Server) {
2929
return func(c *config.Server) {
3030
c.PublicAddr = publicAddr
3131
}
3232
}
3333

34-
// Attributes are server settings that are accessible via the API.
34+
// Attributes sets server attributes that are applied by the server and accessible via the Lookup method.
3535
func (Server) Attributes(attributes *attributes.Attributes) func(*config.Server) {
3636
return func(c *config.Server) {
3737
c.Attributes = attributes
3838
}
3939
}
4040

41-
// GRPCOptions provide []grpc.ServerOption to the server.
41+
// GRPCOptions adds gRPC server options to the server.
4242
func (Server) GRPCOptions(options ...grpc.ServerOption) func(*config.Server) {
4343
return func(c *config.Server) {
4444
c.GRPCOptions = append(c.GRPCOptions, options...)

0 commit comments

Comments
 (0)