Skip to content

Commit

Permalink
[ITOM-83231] - support multiple proxies in tracing proxy
Browse files Browse the repository at this point in the history
[ITOM-83231] - support multiple proxies in tracing proxy
---------

Co-authored-by: lokesh.balla <lokesh.balla@hpe.com>
  • Loading branch information
LokeshOpsramp and lokesh.balla committed Mar 18, 2024
1 parent ad60243 commit dd9d5f6
Show file tree
Hide file tree
Showing 65 changed files with 7,254 additions and 801 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21.5'
go-version: '1.22.1'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.1
version: v1.55.2
args: "--timeout 2m -v"
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
uses: actions/checkout@v3
- uses: addnab/docker-run-action@v3
with:
image: golang:1.21.6-bullseye
image: golang:1.22.1-bullseye
options: -v ${{ github.workspace }}:${{ github.workspace }} --env IS_GITHUB_ACTION=true --env VERSION_TAG=${{ github.event.release.tag_name }}
run: |
cd ${{ github.workspace }}
Expand Down Expand Up @@ -39,8 +39,8 @@ jobs:
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
# manually download and install golang
curl -L -O https://go.dev/dl/go1.21.6.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz
curl -L -O https://go.dev/dl/go1.22.1.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.1.linux-amd64.tar.gz
# setup env and build the rpm package
cd ${{ github.workspace }}
Expand Down
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
---
linters:
enable:
- whitespace
- misspell
- gofumpt
- gocritic

linters-settings:
gofumpt:
module-path: "github.com/opsramp/tracing-proxy"
extra-rules: true
gocritic:
enabled-checks:
- ruleguard
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM --platform=$BUILDPLATFORM golang:1.21.6-alpine3.19 as builder
FROM --platform=$BUILDPLATFORM golang:1.22.1-alpine3.19 as builder

ARG TARGETOS
ARG TARGETARCH

RUN apk update && apk add --no-cache git bash ca-certificates && update-ca-certificates

ARG BUILD_ID="17.0.2"
ARG BUILD_ID="17.0.4"

WORKDIR /app

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ deps:
go mod download

vet:
golangci-lint run ./...
golangci-lint run --fix ./...

vuln:
govulncheck ./...
Expand Down
1 change: 0 additions & 1 deletion build/vm/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func main() {

systemctl := exec.Command("systemctl", "--version").Run()
if systemctl == nil { // checking os type here

_ = exec.Command("cp", "/opt/opsramp/service_files/tracing-proxy.service", "/etc/systemd/system/tracing-proxy.service").Run()
_ = exec.Command("chmod", "0644", "/etc/systemd/system/tracing-proxy").Run()
_ = exec.Command("rm", "-rf", "/opt/opsramp/service_files").Run()
Expand Down
104 changes: 52 additions & 52 deletions cmd/tracing-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net"
"net/http"
"os"
"os/signal"
"syscall"
Expand All @@ -13,14 +12,17 @@ import (
"github.com/facebookgo/inject"
"github.com/facebookgo/startstop"
flag "github.com/jessevdk/go-flags"
"github.com/opsramp/libtrace-go"
"github.com/opsramp/libtrace-go/transmission"
"github.com/opsramp/tracing-proxy/app"
"github.com/opsramp/tracing-proxy/collect"
"github.com/opsramp/tracing-proxy/config"
"github.com/opsramp/tracing-proxy/internal/peer"
"github.com/opsramp/tracing-proxy/logger"
"github.com/opsramp/tracing-proxy/metrics"
"github.com/opsramp/tracing-proxy/pkg/libtrace"
"github.com/opsramp/tracing-proxy/pkg/libtrace/constants"
"github.com/opsramp/tracing-proxy/pkg/libtrace/transmission"
"github.com/opsramp/tracing-proxy/pkg/retry"
"github.com/opsramp/tracing-proxy/proxy"
"github.com/opsramp/tracing-proxy/sample"
"github.com/opsramp/tracing-proxy/service/debug"
"github.com/opsramp/tracing-proxy/sharder"
Expand Down Expand Up @@ -87,7 +89,18 @@ func main() {
}

// get desired implementation for each dependency to inject
lgr := logger.GetLoggerImplementation()
lc, err := c.GetLogrusConfig()
if err != nil {
fmt.Printf("unable to load config: %+v\n", err)
os.Exit(1)
}
lgr := logger.GetLoggerImplementation(
lc.LogFormatter,
lc.LogOutput,
lc.File.FileName,
lc.File.MaxSize,
lc.File.MaxBackups,
lc.File.Compress)
collector := collect.GetCollectorImplementation(c)
metricsConfig := metrics.GetMetricsImplementation("")
shrdr := sharder.GetSharderImplementation(c)
Expand All @@ -105,38 +118,6 @@ func main() {
os.Exit(1)
}

// set proxy details
proxyConfig := c.GetProxyConfig()
proxyUrl := ""
if proxyConfig.Host != "" && proxyConfig.Protocol != "" {
logrusLogger.Info("Proxy Configuration found, setting up proxy for Traces")
proxyUrl = fmt.Sprintf("%s://%s:%d/", proxyConfig.Protocol, proxyConfig.Host, proxyConfig.Port)
if proxyConfig.Username != "" && proxyConfig.Password != "" {
proxyUrl = fmt.Sprintf("%s://%s:%s@%s:%d", proxyConfig.Protocol, proxyConfig.Username, proxyConfig.Password, proxyConfig.Host, proxyConfig.Port)
logrusLogger.Info("Using Authentication for ProxyConfiguration Communication for Traces")
}
os.Setenv("HTTPS_PROXY", proxyUrl)
os.Setenv("HTTP_PROXY", proxyUrl)
}

// upstreamTransport is the http transport used to send things on to OpsRamp
upstreamTransport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 10 * time.Second,
}).DialContext,
TLSHandshakeTimeout: 15 * time.Second,
}

// peerTransport is the http transport used to send things to a local peer
peerTransport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 3 * time.Second,
}).DialContext,
TLSHandshakeTimeout: 1200 * time.Millisecond,
}

upstreamMetricsConfig := metrics.GetMetricsImplementation("upstream")
peerMetricsConfig := metrics.GetMetricsImplementation("peer")

Expand All @@ -153,16 +134,23 @@ func main() {
logsEndpoint := c.GetLogsEndpoint()
sendEvents := c.GetSendEvents()

// set proxy details
prxy := proxy.NewProxy(c.GetProxyConfig(), opsrampAPI, logsEndpoint, authConfig.Endpoint, c.GetMetricsConfig().OpsRampAPI)
prxy.Logger = lgr
// connect to working proxy at start-up
_ = prxy.SwitchProxy()

lgr.Info().Logf("valid proxy config received: %d", prxy.Len())

userAgentAddition := "tracing-proxy/" + CollectorVersion
upstreamClient, err := libtrace.NewClient(libtrace.ClientConfig{ // nolint:all
Logger: logrusLogger,
Logger: lgr,
Transmission: &transmission.TraceProxy{
MaxBatchSize: c.GetMaxBatchSize(),
BatchTimeout: c.GetBatchTimeout(),
MaxConcurrentBatches: libtrace.DefaultMaxConcurrentBatches,
MaxConcurrentBatches: constants.DefaultMaxConcurrentBatches,
PendingWorkCapacity: uint(c.GetUpstreamBufferSize()),
UserAgentAddition: userAgentAddition,
Transport: upstreamTransport,
BlockOnSend: true,
EnableMsgpackEncoding: false,
Metrics: upstreamMetricsConfig,
Expand All @@ -172,19 +160,20 @@ func main() {
AuthTokenEndpoint: authConfig.Endpoint,
AuthTokenKey: authConfig.Key,
AuthTokenSecret: authConfig.Secret,
ApiHost: opsrampAPI,
TraceEndpoint: opsrampAPI,
TenantId: authConfig.TenantId,
Dataset: dataset,
RetrySettings: &transmission.RetrySettings{
RetrySettings: &retry.Config{
InitialInterval: retryConfig.InitialInterval,
RandomizationFactor: retryConfig.RandomizationFactor,
Multiplier: retryConfig.Multiplier,
MaxInterval: retryConfig.MaxInterval,
MaxElapsedTime: retryConfig.MaxElapsedTime,
},
Logger: logrusLogger,
Logger: lgr,
LogsEndpoint: logsEndpoint,
SendEvents: sendEvents,
Proxy: prxy,
},
})
if err != nil {
Expand All @@ -193,34 +182,34 @@ func main() {
}

peerClient, err := libtrace.NewClient(libtrace.ClientConfig{ // nolint:all
Logger: logrusLogger,
Logger: lgr,
Transmission: &transmission.TraceProxy{
MaxBatchSize: c.GetMaxBatchSize(),
BatchTimeout: c.GetBatchTimeout(),
MaxConcurrentBatches: libtrace.DefaultMaxConcurrentBatches,
MaxConcurrentBatches: constants.DefaultMaxConcurrentBatches,
PendingWorkCapacity: uint(c.GetPeerBufferSize()),
UserAgentAddition: userAgentAddition,
Transport: peerTransport,
DisableCompression: !c.GetCompressPeerCommunication(),
EnableMsgpackEncoding: false,
Metrics: peerMetricsConfig,
IsPeer: true,
AuthTokenEndpoint: authConfig.Endpoint,
AuthTokenKey: authConfig.Key,
AuthTokenSecret: authConfig.Secret,
ApiHost: opsrampAPI,
TraceEndpoint: opsrampAPI,
TenantId: authConfig.TenantId,
Dataset: dataset,
RetrySettings: &transmission.RetrySettings{
RetrySettings: &retry.Config{
InitialInterval: retryConfig.InitialInterval,
RandomizationFactor: retryConfig.RandomizationFactor,
Multiplier: retryConfig.Multiplier,
MaxInterval: retryConfig.MaxInterval,
MaxElapsedTime: retryConfig.MaxElapsedTime,
},
Logger: logrusLogger,
Logger: lgr,
LogsEndpoint: logsEndpoint,
SendEvents: sendEvents,
Proxy: prxy,
},
})
if err != nil {
Expand All @@ -242,10 +231,21 @@ func main() {
&inject.Object{Value: c},
&inject.Object{Value: peers},
&inject.Object{Value: lgr},
&inject.Object{Value: upstreamTransport, Name: "upstreamTransport"},
&inject.Object{Value: peerTransport, Name: "peerTransport"},
&inject.Object{Value: &transmit.DefaultTransmission{LibhClient: upstreamClient, Name: "upstream_"}, Name: "upstreamTransmission"},
&inject.Object{Value: &transmit.DefaultTransmission{LibhClient: peerClient, Name: "peer_"}, Name: "peerTransmission"},
&inject.Object{Value: prxy, Name: "proxyConfig"},
&inject.Object{
Name: "upstreamTransmission",
Value: &transmit.DefaultTransmission{
Name: "upstream_",
Client: upstreamClient,
},
},
&inject.Object{
Name: "peerTransmission",
Value: &transmit.DefaultTransmission{
Name: "peer_",
Client: peerClient,
},
},
&inject.Object{Value: shrdr},
&inject.Object{Value: collector},
&inject.Object{Value: metricsConfig, Name: "metrics"},
Expand Down
8 changes: 4 additions & 4 deletions collect/cache/cuckoo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package cache

import (
"fmt"
"github.com/dgryski/go-wyhash"
"github.com/opsramp/tracing-proxy/metrics"
"github.com/sourcegraph/conc/pool"
"math/rand"

"testing"
"time"

"github.com/dgryski/go-wyhash"
"github.com/opsramp/tracing-proxy/metrics"
"github.com/sourcegraph/conc/pool"
)

// genID returns a random hex string of length numChars
Expand Down
2 changes: 1 addition & 1 deletion collect/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func (i *InMemCollector) processSpan(sp *types.Span) {
// dealWithSentTrace handles a span that has arrived after the sampling decision
// on the trace has already been made, and it obeys that decision by either
// sending the span immediately or dropping it.
func (i *InMemCollector) dealWithSentTrace(keep bool, sampleRate uint, spanCount uint, sp *types.Span) {
func (i *InMemCollector) dealWithSentTrace(keep bool, sampleRate, spanCount uint, sp *types.Span) {
if i.Config.GetIsDryRun() {
field := i.Config.GetDryRunFieldName()
// if dry run mode is enabled, we keep all traces and mark the spans with the sampling decision
Expand Down
8 changes: 6 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package config

import "time"
import (
"time"

"github.com/opsramp/tracing-proxy/pkg/retry"
)

// Config defines the interface the rest of the code uses to get items from the
// config. There are different implementations of the config using different
Expand Down Expand Up @@ -171,7 +175,7 @@ type Config interface {
// GetAuthConfig return the authentication configuration
GetAuthConfig() AuthConfiguration

GetRetryConfig() *RetryConfiguration
GetRetryConfig() *retry.Config

GetTenantId() (string, error)

Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// creates two temporary toml files from the strings passed in and returns their filenames
func createTempConfigs(t *testing.T, configBody string, rulesBody string) (string, string) {
func createTempConfigs(t *testing.T, configBody, rulesBody string) (string, string) {
tmpDir, err := os.MkdirTemp("", "")
assert.NoError(t, err)

Expand Down
Loading

0 comments on commit dd9d5f6

Please sign in to comment.