Skip to content

Commit

Permalink
Hera otel integration (#402)
Browse files Browse the repository at this point in the history
* changes for otel integration

* disable otel unittests as part of code coverage tests

---------

Co-authored-by: Rajesh S <[email protected]>
  • Loading branch information
rasamala83 and rajesh-1983 authored Dec 7, 2024
1 parent b94420d commit 0be08e2
Show file tree
Hide file tree
Showing 24 changed files with 2,930 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.18.2
go-version: 1.20.14
- name: Install GO Modules
run: |
go mod tidy
Expand All @@ -41,7 +41,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.18.2
go-version: 1.20.14
- name: Install GO Modules
run: |
go mod tidy
Expand Down
23 changes: 21 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
module github.com/paypal/hera

go 1.18
go 1.20

require (
github.com/go-sql-driver/mysql v1.7.1
github.com/godror/godror v0.26.3
github.com/lib/pq v1.10.3
go.opentelemetry.io/otel v1.24.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.24.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.24.0
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.24.0
go.opentelemetry.io/otel/metric v1.24.0
go.opentelemetry.io/otel/sdk v1.24.0
go.opentelemetry.io/otel/sdk/metric v1.24.0
go.opentelemetry.io/proto/otlp v1.2.0
google.golang.org/protobuf v1.34.1
)

require (
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/go-logfmt/logfmt v0.5.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/grpc v1.64.0 // indirect
)
52 changes: 47 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,19 +1,61 @@
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/godror/godror v0.26.3 h1:V+z+Q/OBGgmmYzuAwyJzpcn4LsPF4Ev0xHAea68V00c=
github.com/godror/godror v0.26.3/go.mod h1:1QCn6oXh3r+IlB3DLE8V6qkHXLSHd18a3Hw7szQ9/3Y=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
github.com/lib/pq v1.10.3 h1:v9QZf2Sn6AmjXtQeFpdoq/eaNtYP6IN+7lcrygsIAtg=
github.com/lib/pq v1.10.3/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.24.0 h1:f2jriWfOdldanBwS9jNBdeOKAQN7b4ugAMaNu1/1k9g=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.24.0/go.mod h1:B+bcQI1yTY+N0vqMpoZbEN7+XU4tNM0DmUiOwebFJWI=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.24.0 h1:mM8nKi6/iFQ0iqst80wDHU2ge198Ye/TfN0WBS5U24Y=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.24.0/go.mod h1:0PrIIzDteLSmNyxqcGYRL4mDIo8OTuBAOI/Bn1URxac=
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.24.0 h1:JYE2HM7pZbOt5Jhk8ndWZTUWYOVift2cHjXVMkPdmdc=
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.24.0/go.mod h1:yMb/8c6hVsnma0RpsBMNo0fEiQKeclawtgaIaOp2MLY=
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg=
go.opentelemetry.io/otel/sdk/metric v1.24.0 h1:yyMQrPzF+k88/DbH7o4FMAs80puqd+9osbiBrJrz/w8=
go.opentelemetry.io/otel/sdk/metric v1.24.0/go.mod h1:I6Y5FjH6rvEnTTAYQz3Mmv2kl6Ek5IIrmwTLqMrrOE0=
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
go.opentelemetry.io/proto/otlp v1.2.0 h1:pVeZGk7nXDC9O2hncA6nHldxEjm6LByfA2aN8IOkz94=
go.opentelemetry.io/proto/otlp v1.2.0/go.mod h1:gGpR8txAl5M03pDhMC79G6SdqNV26naRm/KDsgaHD8A=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 h1:P8OJ/WCl/Xo4E4zoe4/bifHpSmmKwARqyqE4nW6J2GQ=
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5/go.mod h1:RGnPtTG7r4i8sPlNyDeikXF99hMM+hN6QMm4ooG9g2g=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 h1:AgADTJarZTBqgjiUzRgfaBchgYB3/WFTC80GPwsMcRI=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
51 changes: 49 additions & 2 deletions lib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/paypal/hera/cal"
"github.com/paypal/hera/config"
"github.com/paypal/hera/utility/logger"
otelconfig "github.com/paypal/hera/utility/logger/otel/config"

"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -236,7 +238,7 @@ func parseMapStrStr(encoded string) map[string]string {
}

// InitConfig initializes the configuration, both the static configuration (from hera.txt) and the dynamic configuration
func InitConfig() error {
func InitConfig(poolName string) error {
currentDir, abserr := filepath.Abs(filepath.Dir(os.Args[0]))

if abserr != nil {
Expand Down Expand Up @@ -488,9 +490,39 @@ func InitConfig() error {
gAppConfig.MaxDesiredHealthyWorkerPct = 90
}

//Initialize OTEL configs
initializeOTELConfigs(cdb, poolName)
if logger.GetLogger().V(logger.Info) {
otelconfig.OTelConfigData.Dump()
}
return nil
}

// This function takes care of initialize OTEL configuration
func initializeOTELConfigs(cdb config.Config, poolName string) {
otelconfig.OTelConfigData = &otelconfig.OTelConfig{}
//TODO initialize the values
otelconfig.OTelConfigData.Enabled = cdb.GetOrDefaultBool("enable_otel", false)
otelconfig.OTelConfigData.SkipCalStateLog = cdb.GetOrDefaultBool("skip_cal_statelog", false)
otelconfig.OTelConfigData.MetricNamePrefix = cdb.GetOrDefaultString("otel_metric_prefix", "pp.occ")
otelconfig.OTelConfigData.Host = cdb.GetOrDefaultString("otel_agent_host", "localhost")
otelconfig.OTelConfigData.MetricsPort = cdb.GetOrDefaultInt("otel_agent_metrics_port", 4318)
otelconfig.OTelConfigData.TracePort = cdb.GetOrDefaultInt("otel_agent_trace_port", 4318)
otelconfig.OTelConfigData.OtelMetricGRPC = cdb.GetOrDefaultBool("otel_agent_use_grpc_metric", false)
otelconfig.OTelConfigData.OtelTraceGRPC = cdb.GetOrDefaultBool("otel_agent_use_grpc_trace", false)
otelconfig.OTelConfigData.MetricsURLPath = cdb.GetOrDefaultString("otel_agent_metrics_uri", "")
otelconfig.OTelConfigData.TraceURLPath = cdb.GetOrDefaultString("otel_agent_trace_uri", "")
otelconfig.OTelConfigData.PoolName = poolName
otelconfig.OTelConfigData.UseTls = cdb.GetOrDefaultBool("otel_use_tls", false)
otelconfig.OTelConfigData.TLSCertPath = cdb.GetOrDefaultString("otel_tls_cert_path", "")
otelconfig.OTelConfigData.ResolutionTimeInSec = cdb.GetOrDefaultInt("otel_resolution_time_in_sec", 1)
otelconfig.OTelConfigData.ExporterTimeout = cdb.GetOrDefaultInt("otel_exporter_time_in_sec", 30)
otelconfig.OTelConfigData.EnableRetry = cdb.GetOrDefaultBool("otel_enable_exporter_retry", false)
otelconfig.OTelConfigData.ResourceType = gAppConfig.StateLogPrefix
otelconfig.OTelConfigData.OTelErrorReportingInterval = cdb.GetOrDefaultInt("otel_error_reporting_interval_in_sec", 60)
otelconfig.SetOTelIngestToken(cdb.GetOrDefaultString("otel_ingest_token", ""))
}

func LogOccConfigs() {
whiteListConfigs := map[string]map[string]interface{}{
"BACKLOG": {
Expand All @@ -503,6 +535,18 @@ func LogOccConfigs() {
"bouncer_startup_delay": gAppConfig.BouncerStartupDelay,
"bouncer_poll_interval_ms": gAppConfig.BouncerPollInterval,
},
"OTEL": {
"enable_otel": otelconfig.OTelConfigData.Enabled,
"otel_use_tls": otelconfig.OTelConfigData.UseTls,
"skip_cal_statelog": otelconfig.OTelConfigData.SkipCalStateLog,
"otel_agent_host": otelconfig.OTelConfigData.Host,
"otel_agent_metrics_port": otelconfig.OTelConfigData.MetricsPort,
"otel_agent_trace_port": otelconfig.OTelConfigData.TracePort,
"otel_agent_metrics_uri": otelconfig.OTelConfigData.MetricsURLPath,
"otel_agent_trace_uri": otelconfig.OTelConfigData.TraceURLPath,
"otel_resolution_time_in_sec": otelconfig.OTelConfigData.ResolutionTimeInSec,
"otel_error_reporting_interval_in_sec": otelconfig.OTelConfigData.OTelErrorReportingInterval,
},
"PROFILE": {
"enable_profile": gAppConfig.EnableProfile,
"profile_http_port": gAppConfig.ProfileHTTPPort,
Expand Down Expand Up @@ -618,6 +662,10 @@ func LogOccConfigs() {
if !gAppConfig.BouncerEnabled {
continue
}
case "OTEL":
if !otelconfig.OTelConfigData.Enabled {
continue
}
case "PROFILE":
if !gAppConfig.EnableProfile {
continue
Expand Down Expand Up @@ -679,7 +727,6 @@ func LogOccConfigs() {
}
evt.Completed()
}

}

// CheckOpsConfigChange checks if the ops config file needs to be reloaded and reloads it if necessary.
Expand Down
30 changes: 25 additions & 5 deletions lib/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
package lib

import (
"context"
"flag"
"fmt"
otellogger "github.com/paypal/hera/utility/logger/otel"
otelconfig "github.com/paypal/hera/utility/logger/otel/config"
"math/rand"
"os"
"os/signal"
Expand All @@ -36,6 +39,9 @@ func Run() {
signal.Ignore(syscall.SIGPIPE)
mux_process_id := syscall.Getpid()

// Defer release resource in case of any abnormal exit of for application
defer handlePanicAndReleaseResource(mux_process_id)

namePtr := flag.String("name", "", "module name in v$session table")
flag.Parse()

Expand All @@ -50,7 +56,7 @@ func Run() {

rand.Seed(time.Now().Unix())

err := InitConfig()
err := InitConfig(*namePtr)
if err != nil {
if logger.GetLogger().V(logger.Alert) {
logger.GetLogger().Log(logger.Alert, "failed to initialize configuration:", err.Error())
Expand Down Expand Up @@ -106,7 +112,24 @@ func Run() {
caltxn.SetCorrelationID("runtxn")
caltxn.Completed()

GetStateLog().SetStartTime(time.Now())
//Initialize OTEL
if otelconfig.OTelConfigData.Enabled {
shutdownFunc, err := otellogger.Init(context.Background())
if err != nil {
logger.GetLogger().Log(logger.Alert, fmt.Sprintf("failed to initialize OTEL, err: %v", err))
evt := cal.NewCalEvent("OTEL_INIT", *namePtr, "2", fmt.Sprintf("erro: %v", err))
evt.Completed()
if otelconfig.OTelConfigData.SkipCalStateLog {
logger.GetLogger().Log(logger.Alert, fmt.Sprintf("OTEL initialization failed. Only the OTEL state-log has been enabled. It is not safe to start the server"))
FullShutdown()
}
}
GetStateLog().SetStartTime(time.Now())
defer otellogger.StopMetricCollection() //Stop sending metrics data
defer shutdownFunc(context.Background()) //During exit from mux, this will takecare of OTEL providers clean-up
} else {
GetStateLog().SetStartTime(time.Now())
}

go func() {
sleep := time.Duration(GetConfig().ConfigReloadTimeMs)
Expand Down Expand Up @@ -192,9 +215,6 @@ func Run() {
cal.ReleaseCxtResource()
}()

// Defer release resource in case of any abnormal exit of for application
defer handlePanicAndReleaseResource(mux_process_id)

<-GetWorkerBrokerInstance().Stopped()
}

Expand Down
Loading

0 comments on commit 0be08e2

Please sign in to comment.