Skip to content

Commit c23ea67

Browse files
varkey98test
andauthored
adding proto to the go module (#164)
Co-authored-by: test <[email protected]>
1 parent 1259231 commit c23ea67

File tree

6 files changed

+232
-6
lines changed

6 files changed

+232
-6
lines changed

gen/go/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.19
55
require (
66
github.com/ghodss/yaml v1.0.0
77
github.com/stretchr/testify v1.9.0
8-
google.golang.org/protobuf v1.34.1
8+
google.golang.org/protobuf v1.34.2
99
)
1010

1111
require (

gen/go/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
88
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
99
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
1010
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
11-
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
12-
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
11+
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
12+
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
1313
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1414
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1515
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=

gen/go/proto/v1/config.proto

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
syntax = "proto3";
2+
3+
package hypertrace.agent.config.v1;
4+
5+
import "google/protobuf/wrappers.proto";
6+
7+
option go_package = "github.com/hypertrace/agent-config/gen/go/v1";
8+
option java_package = "org.hypertrace.agent.config.v1";
9+
option csharp_namespace = "Hypertrace.Agent.Config.V1";
10+
11+
// AgentConfig covers the config for agents.
12+
// The config uses wrappers for primitive types to allow nullable values.
13+
// The nullable values are used for instance to explicitly disable data capture or secure connection.
14+
// Since the wrappers change structure of the objects the marshalling and unmarshalling
15+
// have to be done via protobuf marshallers.
16+
message AgentConfig {
17+
// service_name identifies the service/process running e.g. "my service"
18+
google.protobuf.StringValue service_name = 1;
19+
20+
// reporting holds the reporting settings for the agent
21+
Reporting reporting = 2;
22+
23+
// data_capture describes the data being captured by instrumentation
24+
DataCapture data_capture = 3;
25+
26+
// propagation_formats list the supported propagation formats
27+
repeated PropagationFormat propagation_formats = 4;
28+
29+
// when `false`, disables the agent
30+
google.protobuf.BoolValue enabled = 5;
31+
32+
// javaagent has the configs specific to javaagent
33+
JavaAgent javaagent = 6;
34+
35+
// resource_attributes map define the static list of resources which is configured on the tracer
36+
map<string, string> resource_attributes = 7;
37+
38+
// telemetry
39+
Telemetry telemetry = 8;
40+
41+
// Goagent specific config
42+
GoAgent goagent = 9;
43+
}
44+
45+
// Reporting covers the options related to the mechanics for sending data to the
46+
// tracing server o collector.
47+
message Reporting {
48+
// endpoint represents the endpoint for reporting the traces
49+
// For ZIPKIN reporter type use http://api.traceable.ai:9411/api/v2/spans
50+
// For OTLP reporter type use http://api.traceable.ai:4317
51+
google.protobuf.StringValue endpoint = 1;
52+
53+
// when `true`, connects to endpoints over TLS.
54+
google.protobuf.BoolValue secure = 2;
55+
56+
// user specific token to access Traceable API
57+
google.protobuf.StringValue token = 3;
58+
59+
// reporter type for traces.
60+
TraceReporterType trace_reporter_type = 5;
61+
62+
// Certificate file containing the CA to verify the server's certificate.
63+
// This is for private certificates.
64+
// If this is set then `secure` above should also be set to `true`.
65+
google.protobuf.StringValue cert_file = 6;
66+
67+
// metric_endpoint represents the endpoint for reporting the metrics.
68+
// For OTLP metric reporter type use http://api.traceable.ai:4317
69+
google.protobuf.StringValue metric_endpoint = 7;
70+
71+
// reporter type for metrics.
72+
MetricReporterType metric_reporter_type = 8;
73+
74+
// When `true`, modifies grpc resolver to use dns instead of passthrough and configure round robin client side loadbalancing
75+
google.protobuf.BoolValue enable_grpc_loadbalancing = 9;
76+
}
77+
78+
// Message describes what message should be considered for certain DataCapture option
79+
message Message {
80+
// when `false` it disables the capture for the request in a client/request operation
81+
google.protobuf.BoolValue request = 1;
82+
83+
// when `false` it disables the capture for the response in a client/request operation
84+
google.protobuf.BoolValue response = 2;
85+
}
86+
87+
// DataCapture describes the elements to be captured by the agent instrumentation
88+
message DataCapture {
89+
// http_headers enables/disables the capture of the request/response headers in HTTP
90+
Message http_headers = 1;
91+
92+
// http_body enables/disables the capture of the request/response body in HTTP
93+
Message http_body = 2;
94+
95+
// rpc_metadata enables/disables the capture of the request/response metadata in RPC
96+
Message rpc_metadata = 3;
97+
98+
// rpc_body enables/disables the capture of the request/response body in RPC
99+
Message rpc_body = 4;
100+
101+
// body_max_size_bytes is the maximum size of captured body in bytes.
102+
// Default should be 131_072 (128 KiB).
103+
google.protobuf.Int32Value body_max_size_bytes = 5;
104+
105+
// body_max_processing_size_bytes is maximum size of body being processed by filters in bytes.
106+
// Default should be 1_048_576 (1MB).
107+
//
108+
// For uncompressed bodies we capture all bytes up to `body_max_processing_size_bytes`
109+
// in memory and pass that through the filter.
110+
// For compressed and GRPC bodies, if the size of the body is larger than this, we ignore
111+
// it entirely, otherwise we decompress/decode the body and then pass it to the filter.
112+
google.protobuf.Int32Value body_max_processing_size_bytes = 6;
113+
114+
// Array of allowed content type substrings to record
115+
// default should be json, x-www-form-urlencoded
116+
// ex: ["json"] will record any request bodies that have a content-type header that includes "json"
117+
repeated google.protobuf.StringValue allowed_content_types = 10;
118+
}
119+
120+
// PropagationFormat represents the propagation formats supported by agents
121+
enum PropagationFormat {
122+
// B3 propagation format, agents should support both multi and single value formats
123+
// see https://github.com/openzipkin/b3-propagation
124+
B3 = 0;
125+
126+
// W3C Propagation format
127+
// see https://www.w3.org/TR/trace-context/
128+
TRACECONTEXT = 1;
129+
}
130+
131+
// TraceReporterType represents the reporting format for trace data.
132+
enum TraceReporterType {
133+
134+
// Default to none. Agent will use it's default reporting type
135+
UNSPECIFIED = 0;
136+
137+
// Zipkin protobuf reporting format.
138+
// see https://github.com/openzipkin/zipkin-api
139+
ZIPKIN = 1;
140+
141+
// OpenTelemetry protobuf reporting format.
142+
// see https://github.com/open-telemetry/opentelemetry-proto
143+
OTLP = 2;
144+
145+
// Logging reporting format
146+
LOGGING = 3;
147+
148+
// Disable trace reporting
149+
NONE = 4;
150+
151+
// OTLP over http
152+
OTLP_HTTP = 5;
153+
}
154+
155+
// MetricReporterType represents the reporting format for metric data.
156+
enum MetricReporterType {
157+
158+
// Default to none. Agent will use it's default reporting type
159+
METRIC_REPORTER_TYPE_UNSPECIFIED = 0;
160+
161+
// OpenTelemetry protobuf reporting format.
162+
// see https://github.com/open-telemetry/opentelemetry-proto
163+
METRIC_REPORTER_TYPE_OTLP = 1;
164+
165+
// Prometheus exposition format.
166+
// see https://github.com/prometheus/docs/blob/main/content/docs/instrumenting/exposition_formats.md
167+
METRIC_REPORTER_TYPE_PROMETHEUS = 2;
168+
169+
// Logging reporting format
170+
METRIC_REPORTER_TYPE_LOGGING = 3;
171+
172+
// Disable metric reporting
173+
METRIC_REPORTER_TYPE_NONE = 4;
174+
}
175+
176+
// JavaAgent has the configs specific to javaagent
177+
message JavaAgent {
178+
// filter_jar_paths is the list of path to filter jars, separated by `,`
179+
repeated google.protobuf.StringValue filter_jar_paths = 1;
180+
}
181+
182+
// GoAgent has the configs specific to goagent
183+
message GoAgent {
184+
// use the custom batch_span_processor adapted from the one in opentelemetry go
185+
// and supports some additional metrics
186+
google.protobuf.BoolValue use_custom_bsp = 1;
187+
}
188+
189+
// Telemetry has config for agent telemetry: traces and metrics on agent's
190+
// performance and events.
191+
message Telemetry {
192+
// when `true`, an internal span is created and exported when the agent is initialized and started.
193+
// It's useful to denote when the application the agent is in started.
194+
google.protobuf.BoolValue startup_span_enabled = 1;
195+
196+
// Whether to capture metrics or not. The metrics will be otel go metrics.
197+
// See https://github.com/open-telemetry/opentelemetry-go/tree/main/metric
198+
google.protobuf.BoolValue metrics_enabled = 2;
199+
}

gen/go/v1/config.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/go-generator/cmd/generator/main.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"flag"
55
"fmt"
66
"go/format"
7+
"io"
78
"log"
89
"os"
910
"path"
@@ -275,6 +276,11 @@ func writeLoadersForProto(cmdDir, protoFilepath, outDir, optModule, envPrefix st
275276
return fmt.Errorf("failed to write loaders file: %v", err)
276277
}
277278

279+
err = copyProtoFile(f, genDstDir)
280+
if err != nil {
281+
return fmt.Errorf("failed to write proto file: %v", err)
282+
}
283+
278284
return nil
279285
}
280286

@@ -332,3 +338,25 @@ func writeToFile(filename string, content []byte) error {
332338

333339
return nil
334340
}
341+
342+
func copyProtoFile(file *os.File, genDstDir string) error {
343+
_, err := file.Seek(0, io.SeekStart)
344+
if err != nil {
345+
return err
346+
}
347+
348+
protoContent, err := io.ReadAll(file)
349+
if err != nil {
350+
return err
351+
}
352+
353+
err = os.MkdirAll(path.Join(path.Dir(genDstDir), "proto", "v1"), os.ModePerm)
354+
if err != nil {
355+
return err
356+
}
357+
err = writeToFile(path.Join(path.Dir(genDstDir), "proto", "v1", "config.proto"), protoContent)
358+
if err != nil {
359+
return err
360+
}
361+
return nil
362+
}

tools/go-generator/cmd/generator/template.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"html/template"
5-
"io/ioutil"
65
"os"
76
"path"
87
"path/filepath"
@@ -21,7 +20,7 @@ func copyTemplateFiles(srcDir, outDir string, settings Loaders) error {
2120
return nil
2221
}
2322

24-
content, err := ioutil.ReadFile(fpath)
23+
content, err := os.ReadFile(fpath)
2524
if err != nil {
2625
return err
2726
}

0 commit comments

Comments
 (0)