Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding proto to the go module #164

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gen/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/ghodss/yaml v1.0.0
github.com/stretchr/testify v1.9.0
google.golang.org/protobuf v1.34.1
google.golang.org/protobuf v1.34.2
)

require (
Expand Down
4 changes: 2 additions & 2 deletions gen/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
Expand Down
199 changes: 199 additions & 0 deletions gen/go/proto/v1/config.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
syntax = "proto3";

package hypertrace.agent.config.v1;

import "google/protobuf/wrappers.proto";

option go_package = "github.com/hypertrace/agent-config/gen/go/v1";
option java_package = "org.hypertrace.agent.config.v1";
option csharp_namespace = "Hypertrace.Agent.Config.V1";

// AgentConfig covers the config for agents.
// The config uses wrappers for primitive types to allow nullable values.
// The nullable values are used for instance to explicitly disable data capture or secure connection.
// Since the wrappers change structure of the objects the marshalling and unmarshalling
// have to be done via protobuf marshallers.
message AgentConfig {
// service_name identifies the service/process running e.g. "my service"
google.protobuf.StringValue service_name = 1;

// reporting holds the reporting settings for the agent
Reporting reporting = 2;

// data_capture describes the data being captured by instrumentation
DataCapture data_capture = 3;

// propagation_formats list the supported propagation formats
repeated PropagationFormat propagation_formats = 4;

// when `false`, disables the agent
google.protobuf.BoolValue enabled = 5;

// javaagent has the configs specific to javaagent
JavaAgent javaagent = 6;

// resource_attributes map define the static list of resources which is configured on the tracer
map<string, string> resource_attributes = 7;

// telemetry
Telemetry telemetry = 8;

// Goagent specific config
GoAgent goagent = 9;
}

// Reporting covers the options related to the mechanics for sending data to the
// tracing server o collector.
message Reporting {
// endpoint represents the endpoint for reporting the traces
// For ZIPKIN reporter type use http://api.traceable.ai:9411/api/v2/spans
// For OTLP reporter type use http://api.traceable.ai:4317
google.protobuf.StringValue endpoint = 1;

// when `true`, connects to endpoints over TLS.
google.protobuf.BoolValue secure = 2;

// user specific token to access Traceable API
google.protobuf.StringValue token = 3;

// reporter type for traces.
TraceReporterType trace_reporter_type = 5;

// Certificate file containing the CA to verify the server's certificate.
// This is for private certificates.
// If this is set then `secure` above should also be set to `true`.
google.protobuf.StringValue cert_file = 6;

// metric_endpoint represents the endpoint for reporting the metrics.
// For OTLP metric reporter type use http://api.traceable.ai:4317
google.protobuf.StringValue metric_endpoint = 7;

// reporter type for metrics.
MetricReporterType metric_reporter_type = 8;

// When `true`, modifies grpc resolver to use dns instead of passthrough and configure round robin client side loadbalancing
google.protobuf.BoolValue enable_grpc_loadbalancing = 9;
}

// Message describes what message should be considered for certain DataCapture option
message Message {
// when `false` it disables the capture for the request in a client/request operation
google.protobuf.BoolValue request = 1;

// when `false` it disables the capture for the response in a client/request operation
google.protobuf.BoolValue response = 2;
}

// DataCapture describes the elements to be captured by the agent instrumentation
message DataCapture {
// http_headers enables/disables the capture of the request/response headers in HTTP
Message http_headers = 1;

// http_body enables/disables the capture of the request/response body in HTTP
Message http_body = 2;

// rpc_metadata enables/disables the capture of the request/response metadata in RPC
Message rpc_metadata = 3;

// rpc_body enables/disables the capture of the request/response body in RPC
Message rpc_body = 4;

// body_max_size_bytes is the maximum size of captured body in bytes.
// Default should be 131_072 (128 KiB).
google.protobuf.Int32Value body_max_size_bytes = 5;

// body_max_processing_size_bytes is maximum size of body being processed by filters in bytes.
// Default should be 1_048_576 (1MB).
//
// For uncompressed bodies we capture all bytes up to `body_max_processing_size_bytes`
// in memory and pass that through the filter.
// For compressed and GRPC bodies, if the size of the body is larger than this, we ignore
// it entirely, otherwise we decompress/decode the body and then pass it to the filter.
google.protobuf.Int32Value body_max_processing_size_bytes = 6;

// Array of allowed content type substrings to record
// default should be json, x-www-form-urlencoded
// ex: ["json"] will record any request bodies that have a content-type header that includes "json"
repeated google.protobuf.StringValue allowed_content_types = 10;
}

// PropagationFormat represents the propagation formats supported by agents
enum PropagationFormat {
// B3 propagation format, agents should support both multi and single value formats
// see https://github.com/openzipkin/b3-propagation
B3 = 0;

// W3C Propagation format
// see https://www.w3.org/TR/trace-context/
TRACECONTEXT = 1;
}

// TraceReporterType represents the reporting format for trace data.
enum TraceReporterType {

// Default to none. Agent will use it's default reporting type
UNSPECIFIED = 0;

// Zipkin protobuf reporting format.
// see https://github.com/openzipkin/zipkin-api
ZIPKIN = 1;

// OpenTelemetry protobuf reporting format.
// see https://github.com/open-telemetry/opentelemetry-proto
OTLP = 2;

// Logging reporting format
LOGGING = 3;

// Disable trace reporting
NONE = 4;

// OTLP over http
OTLP_HTTP = 5;
}

// MetricReporterType represents the reporting format for metric data.
enum MetricReporterType {

// Default to none. Agent will use it's default reporting type
METRIC_REPORTER_TYPE_UNSPECIFIED = 0;

// OpenTelemetry protobuf reporting format.
// see https://github.com/open-telemetry/opentelemetry-proto
METRIC_REPORTER_TYPE_OTLP = 1;

// Prometheus exposition format.
// see https://github.com/prometheus/docs/blob/main/content/docs/instrumenting/exposition_formats.md
METRIC_REPORTER_TYPE_PROMETHEUS = 2;

// Logging reporting format
METRIC_REPORTER_TYPE_LOGGING = 3;

// Disable metric reporting
METRIC_REPORTER_TYPE_NONE = 4;
}

// JavaAgent has the configs specific to javaagent
message JavaAgent {
// filter_jar_paths is the list of path to filter jars, separated by `,`
repeated google.protobuf.StringValue filter_jar_paths = 1;
}

// GoAgent has the configs specific to goagent
message GoAgent {
// use the custom batch_span_processor adapted from the one in opentelemetry go
// and supports some additional metrics
google.protobuf.BoolValue use_custom_bsp = 1;
}

// Telemetry has config for agent telemetry: traces and metrics on agent's
// performance and events.
message Telemetry {
// when `true`, an internal span is created and exported when the agent is initialized and started.
// It's useful to denote when the application the agent is in started.
google.protobuf.BoolValue startup_span_enabled = 1;

// Whether to capture metrics or not. The metrics will be otel go metrics.
// See https://github.com/open-telemetry/opentelemetry-go/tree/main/metric
google.protobuf.BoolValue metrics_enabled = 2;
}
2 changes: 1 addition & 1 deletion gen/go/v1/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions tools/go-generator/cmd/generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"go/format"
"io"
"log"
"os"
"path"
Expand Down Expand Up @@ -275,6 +276,11 @@ func writeLoadersForProto(cmdDir, protoFilepath, outDir, optModule, envPrefix st
return fmt.Errorf("failed to write loaders file: %v", err)
}

err = copyProtoFile(f, genDstDir)
if err != nil {
return fmt.Errorf("failed to write proto file: %v", err)
}

return nil
}

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

return nil
}

func copyProtoFile(file *os.File, genDstDir string) error {
_, err := file.Seek(0, io.SeekStart)
if err != nil {
return err
}

protoContent, err := io.ReadAll(file)
if err != nil {
return err
}

err = os.MkdirAll(path.Join(path.Dir(genDstDir), "proto", "v1"), os.ModePerm)
if err != nil {
return err
}
err = writeToFile(path.Join(path.Dir(genDstDir), "proto", "v1", "config.proto"), protoContent)
if err != nil {
return err
}
return nil
}
3 changes: 1 addition & 2 deletions tools/go-generator/cmd/generator/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"html/template"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand All @@ -21,7 +20,7 @@ func copyTemplateFiles(srcDir, outDir string, settings Loaders) error {
return nil
}

content, err := ioutil.ReadFile(fpath)
content, err := os.ReadFile(fpath)
if err != nil {
return err
}
Expand Down
Loading