Skip to content

Commit c0343e7

Browse files
committed
Responded to Easwar's comments
1 parent a93ab8b commit c0343e7

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

examples/features/csm_observability/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# CSM Observability
22

3-
This examples shows how to configure CSM Observability for a binary, and shows
4-
what type of telemetry data it can produce for certain RPC's with additional CSM
5-
Labels. The Client accepts configuration from an xDS Control plane as the
6-
default address that it connects to is "xds:///helloworld:50051", but this can
7-
be overridden with the command line flag --addr.
3+
This examples shows how to configure CSM Observability for gRPC client and
4+
server applications (configured once per binary), and shows what type of
5+
telemetry data it can produce for certain RPCs with additional CSM Labels. The
6+
gRPC Client accepts configuration from an xDS Control plane as the default
7+
address that it connects to is "xds:///helloworld:50051", but this can be
8+
overridden with the command line flag --server_addr. This can be plugged into
9+
the steps outlined in the CSM Observability User Guide.
810

911
## Try it (locally if overwritten xDS Address)
1012

@@ -17,6 +19,7 @@ go run client/main.go
1719
```
1820

1921
```
22+
Curl to the port where Prometheus exporter is outputting metrics data:
2023
curl localhost:9464/metrics
2124
```
2225

examples/features/csm_observability/client/main.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,19 @@ import (
3939
)
4040

4141
var (
42-
addr = flag.String("addr", "xds:///helloworld:50051", "the server address to connect to")
43-
promAddr = flag.String("promAddr", ":9464", "the Prometheus exporter endpoint")
42+
addr = flag.String("server_addr", "xds:///helloworld:50051", "the server address to connect to")
43+
promAddr = flag.String("prom_addr", ":9464", "the Prometheus exporter endpoint")
4444
)
4545

4646
func main() {
4747
exporter, err := prometheus.New()
4848
if err != nil {
4949
log.Fatalf("Failed to start prometheus exporter: %v", err)
5050
}
51-
provider := metric.NewMeterProvider(
52-
metric.WithReader(exporter),
53-
)
51+
provider := metric.NewMeterProvider(metric.WithReader(exporter))
5452
go http.ListenAndServe(*promAddr, promhttp.Handler())
5553

56-
ctx := context.Background()
57-
cleanup := csm.EnableObservability(ctx, opentelemetry.Options{MetricsOptions: opentelemetry.MetricsOptions{MeterProvider: provider}})
54+
cleanup := csm.EnableObservability(context.Background(), opentelemetry.Options{MetricsOptions: opentelemetry.MetricsOptions{MeterProvider: provider}})
5855
defer cleanup()
5956

6057
cc, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
@@ -67,11 +64,13 @@ func main() {
6764
// Make a RPC every second. This should trigger telemetry to be emitted from
6865
// the client and the server.
6966
for {
67+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
7068
r, err := c.UnaryEcho(ctx, &echo.EchoRequest{Message: "this is examples/opentelemetry"})
7169
if err != nil {
7270
log.Fatalf("UnaryEcho failed: %v", err)
7371
}
7472
fmt.Println(r)
7573
time.Sleep(time.Second)
74+
cancel()
7675
}
7776
}

examples/features/csm_observability/server/main.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import (
3737
)
3838

3939
var (
40-
addr = flag.String("addr", ":50051", "the server address to connect to")
41-
promAddr = flag.String("promAddr", ":9464", "the Prometheus exporter endpoint")
40+
addr = flag.String("server_addr", ":50051", "the server address to connect to")
41+
promAddr = flag.String("prom_addr", ":9464", "the Prometheus exporter endpoint")
4242
)
4343

4444
type echoServer struct {
@@ -55,26 +55,22 @@ func main() {
5555
if err != nil {
5656
log.Fatalf("Failed to start prometheus exporter: %v", err)
5757
}
58-
provider := metric.NewMeterProvider(
59-
metric.WithReader(exporter),
60-
)
58+
provider := metric.NewMeterProvider(metric.WithReader(exporter))
6159
go http.ListenAndServe(*promAddr, promhttp.Handler())
6260

6361
cleanup := csm.EnableObservability(context.Background(), opentelemetry.Options{MetricsOptions: opentelemetry.MetricsOptions{MeterProvider: provider}})
6462
defer cleanup()
6563

6664
lis, err := net.Listen("tcp", *addr)
6765
if err != nil {
68-
log.Fatalf("failed to listen: %v", err)
66+
log.Fatalf("Failed to listen: %v", err)
6967
}
7068
s := grpc.NewServer()
71-
pb.RegisterEchoServer(s, &echoServer{
72-
addr: *addr,
73-
})
69+
pb.RegisterEchoServer(s, &echoServer{addr: *addr})
7470

75-
log.Printf("serving on %s\n", *addr)
71+
log.Printf("Serving on %s\n", *addr)
7672

7773
if err := s.Serve(lis); err != nil {
78-
log.Fatalf("failed to serve: %v", err)
74+
log.Fatalf("Failed to serve: %v", err)
7975
}
8076
}

0 commit comments

Comments
 (0)