Skip to content

Commit

Permalink
feat: add runtime telemetry to heartbeat (#583)
Browse files Browse the repository at this point in the history
# Description

Please provide a brief description of the changes made in this pull
request.

Add runtime profile metrics to the heartbeat for long term performance
metrics.

## Related Issue

If this pull request is related to any issue, please mention it here.
Additionally, make sure that the issue is assigned to you before
submitting this pull request.

## Checklist

- [ ] I have read the [contributing
documentation](https://retina.sh/docs/contributing).
- [ ] I signed and signed-off the commits (`git commit -S -s ...`). See
[this
documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)
on signing commits.
- [ ] I have correctly attributed the author(s) of the code.
- [ ] I have tested the changes locally.
- [ ] I have followed the project's style guidelines.
- [ ] I have updated the documentation, if necessary.
- [ ] I have added tests, if applicable.

## Screenshots (if applicable) or Testing Completed

Please add any relevant screenshots or GIFs to showcase the changes
made.

## Additional Notes

Add any additional notes or context about the pull request here.

---

Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more
information on how to contribute to this project.
  • Loading branch information
matmerr authored Aug 12, 2024
1 parent 5425b41 commit 50f26ae
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/legacy/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (

const (
logFileName = "retina.log"
heartbeatInterval = 5 * time.Minute
heartbeatInterval = 10 * time.Minute

nodeNameEnvKey = "NODE_NAME"
nodeIPEnvKey = "NODE_IP"
Expand Down
23 changes: 22 additions & 1 deletion pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"runtime"
"runtime/debug"
"strconv"
"sync"
"time"

Expand All @@ -20,6 +21,13 @@ import (
var (
client appinsights.TelemetryClient
version string
mbShift uint64 = 20

// property keys
kernelversion = "kernelversion"
allocatedmem = "allocmem"
sysmem = "sysmem"
goroutines = "goroutines"
)

type Telemetry interface {
Expand Down Expand Up @@ -143,7 +151,20 @@ func (t *TelemetryClient) heartbeat(ctx context.Context) {
t.trackWarning(err, "failed to get kernel version")
}

t.TrackEvent("heartbeat", map[string]string{"kernelversion": kernelVersion})
var m runtime.MemStats
runtime.ReadMemStats(&m)
props := map[string]string{
kernelversion: kernelVersion,
allocatedmem: strconv.FormatUint(bToMb(m.Alloc), 10),
sysmem: strconv.FormatUint(bToMb(m.Sys), 10),
goroutines: strconv.Itoa(runtime.NumGoroutine()),
}

t.TrackEvent("heartbeat", props)
}

func bToMb(b uint64) uint64 {
return b >> mbShift
}

func (t *TelemetryClient) TrackEvent(name string, properties map[string]string) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,7 @@ func TestTelemetryClient_StopPerf(t *testing.T) {
})
}
}

func TestBtoMB(t *testing.T) {
require.Equal(t, uint64(1), bToMb(1048576))
}

0 comments on commit 50f26ae

Please sign in to comment.