Skip to content
Open
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
41 changes: 41 additions & 0 deletions cmd/heplify-server/heplify-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package main

import (
"fmt"
"gopkg.in/DataDog/dd-trace-go.v1/profiler"
"html/template"
"io"
"net/http"
"os"
"os/signal"
Expand All @@ -24,6 +26,38 @@ type server interface {
End()
}

func StartECSProfiler() (func(), error) {
resp, err := http.Get("http://169.254.169.254/latest/meta-data/local-ipv4")
if err != nil {
return nil, fmt.Errorf("cannot query ec2 metadata: %w", err)

}
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("cannot get local IP address: %w", err)
}
host := string(bodyBytes)
os.Setenv("DD_AGENT_HOST", host)

resp.Body.Close()

if err := profiler.Start(
profiler.WithProfileTypes(
profiler.CPUProfile,
profiler.HeapProfile,
profiler.BlockProfile,
profiler.MutexProfile,
profiler.GoroutineProfile,
),
profiler.WithAgentAddr(fmt.Sprintf("%s:8126", host)),
); err != nil {
return nil, err
}
return func() {
profiler.Stop()
}, nil
}

func init() {
var err error
var logging logp.Logging
Expand Down Expand Up @@ -87,6 +121,13 @@ func main() {
os.Exit(0)
}

cancelProfile, err := StartECSProfiler()
if err != nil {
logp.Err("cannot start profiler: %v", err)
os.Exit(1)
}
defer cancelProfile()

startServer := func() {
hep := input.NewHEPInput()
servers = []server{hep}
Expand Down
31 changes: 13 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,25 @@ require (
github.com/VictoriaMetrics/fastcache v1.5.7
github.com/antonmedv/expr v1.8.8
github.com/buger/jsonparser v1.1.1
github.com/cespare/xxhash/v2 v2.1.1
github.com/fortytw2/leaktest v1.3.0 // indirect
github.com/go-sql-driver/mysql v1.5.0
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee // indirect
github.com/gobwas/pool v0.2.0 // indirect
github.com/gobwas/ws v1.0.3
github.com/cespare/xxhash/v2 v2.2.0
github.com/go-sql-driver/mysql v1.6.0
github.com/gobwas/ws v1.2.1
github.com/gogo/protobuf v1.3.2
github.com/golang/snappy v0.0.1
github.com/lib/pq v1.7.0
github.com/mailru/easyjson v0.7.1 // indirect
github.com/golang/snappy v0.0.4
github.com/lib/pq v1.10.2
github.com/negbie/cert v0.0.0-20190324145947-d1018a8fb00f
github.com/negbie/logp v0.0.0-20190313141056-04cebff7f846
github.com/negbie/multiconfig v1.0.0
github.com/olivere/elastic v6.2.33+incompatible
github.com/pelletier/go-toml v1.8.0
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.7.0
github.com/prometheus/common v0.10.0
github.com/pelletier/go-toml v1.9.5
github.com/prometheus/client_golang v1.19.0
github.com/prometheus/common v0.48.0
github.com/robfig/cron/v3 v3.0.1
github.com/sipcapture/golua v0.0.0-20200610090950-538d24098d76
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.8.4
github.com/valyala/bytebufferpool v1.0.0
github.com/valyala/fasttemplate v1.1.1
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
google.golang.org/genproto v0.0.0-20200619004808-3e7fca5c55db // indirect
google.golang.org/grpc v1.29.1
github.com/valyala/fasttemplate v1.2.2
golang.org/x/sync v0.3.0
google.golang.org/grpc v1.57.1
gopkg.in/DataDog/dd-trace-go.v1 v1.63.1
)
Loading