Skip to content

Commit 8ecfd89

Browse files
authored
chore: update metrics service to use v2/telemetry/OtelMetrics (#1719)
* chore: use v2/telemetry/OtelMetrics * chore: remove metrics response * chore: fix alert list tests
1 parent e90c63c commit 8ecfd89

File tree

18 files changed

+98
-104
lines changed

18 files changed

+98
-104
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535

3636
- name: Build Artifacts
3737
env:
38-
HONEYDATASET: ${{ secrets.PROD_HONEYDATASET }}
38+
METRIC_DATASET: ${{ secrets.METRIC_DATASET }}
3939
run: |
4040
make prepare
4141
scripts/release.sh build

.github/workflows/windows-integration.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ jobs:
2828
CI_SUBACCOUNT: ${{ secrets.CI_SUBACCOUNT }}
2929
CI_API_KEY: ${{ secrets.CI_API_KEY }}
3030
CI_API_SECRET: ${{ secrets.CI_API_SECRET }}
31-
HONEYDATASET: ${{ secrets.HONEYDATASET }}
3231
LW_INT_TEST_AWS_ACC: ${{ secrets.LW_INT_TEST_AWS_ACC }}
3332
run: |
3433
Set-ExecutionPolicy Bypass -Scope Process -Force

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ COVERAGEHTML?=coverage.html
1717
GOJUNITOUT?=go-junit.xml
1818
PACKAGENAME?=lacework-cli
1919
CLINAME?=lacework
20-
# Honeycomb variables
21-
HONEYDATASET?=lacework-cli-dev
20+
METRIC_DATASET?=lacework-cli-dev
2221
GO_LDFLAGS="-X github.com/lacework/go-sdk/v2/cli/cmd.Version=$(shell cat VERSION) \
2322
-X github.com/lacework/go-sdk/v2/cli/cmd.GitSHA=$(shell git rev-parse HEAD) \
24-
-X github.com/lacework/go-sdk/v2/cli/cmd.HoneyDataset=$(HONEYDATASET) \
23+
-X github.com/lacework/go-sdk/v2/cli/cmd.MetricDataset=$(METRIC_DATASET) \
2524
-X github.com/lacework/go-sdk/v2/cli/cmd.BuildTime=$(shell date +%Y%m%d%H%M%S)"
2625
GOFLAGS=-mod=vendor
2726
CGO_ENABLED?=0

api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const (
2727
// API v2 Endpoints
2828
apiTokens = "v2/access/tokens" // Auth
2929

30-
apiV2HoneyMetrics = "v2/metrics/honeycomb"
30+
apiV2OtelMetrics = "v2/telemetry/OtelMetrics?dataset=%s"
3131

3232
apiV2UserProfile = "v2/UserProfile"
3333

api/metrics.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package api
2020

2121
import (
22+
"fmt"
2223
"os"
2324
"runtime"
2425
)
@@ -30,18 +31,22 @@ type MetricsService struct {
3031
client *Client
3132
}
3233

33-
func (svc *MetricsService) Send(event Honeyvent) (response HoneyEventResponse, err error) {
34+
func (svc *MetricsService) Send(event MetricEvent) (err error) {
3435
if disabled := os.Getenv(DisableTelemetry); disabled != "" {
35-
return HoneyEventResponse{Data: []Honeyvent{{TraceID: "Telemetry Disabled"}}}, nil
36+
return
3637
}
3738

3839
event.setAccountDetails(*svc.client)
39-
err = svc.client.RequestEncoderDecoder("POST", apiV2HoneyMetrics, event, &response)
40+
event.SampleRate100 = true
41+
event.TelemetrySource = "external"
42+
event.TelemetryType = "customer"
43+
44+
err = svc.client.RequestEncoderDecoder("POST", fmt.Sprintf(apiV2OtelMetrics, event.Dataset), event, nil)
4045
return
4146
}
4247

43-
func NewHoneyvent(version, feature, dataset string) Honeyvent {
44-
event := Honeyvent{
48+
func NewMetricEvent(version, feature, dataset string) MetricEvent {
49+
event := MetricEvent{
4550
Os: runtime.GOOS,
4651
Arch: runtime.GOARCH,
4752
TraceID: newID(),
@@ -53,7 +58,7 @@ func NewHoneyvent(version, feature, dataset string) Honeyvent {
5358
return event
5459
}
5560

56-
func (h *Honeyvent) setAccountDetails(client Client) {
61+
func (h *MetricEvent) setAccountDetails(client Client) {
5762
if h.Account == "" {
5863
h.Account = client.account
5964
}
@@ -62,8 +67,8 @@ func (h *Honeyvent) setAccountDetails(client Client) {
6267
}
6368
}
6469

65-
// Honeyvent defines what a Honeycomb event looks like for the Lacework CLI
66-
type Honeyvent struct {
70+
// MetricEvent defines what a metric event looks like for the Lacework CLI
71+
type MetricEvent struct {
6772
Version string `json:"version"`
6873
CfgVersion int `json:"config_version"`
6974
Os string `json:"os"`
@@ -89,15 +94,13 @@ type Honeyvent struct {
8994
SpanID string `json:"trace.span_id,omitempty"`
9095
ParentID string `json:"trace.parent_id,omitempty"`
9196
ContextID string `json:"trace.context_id,omitempty"`
92-
}
9397

94-
type HoneyEventResponse struct {
95-
Data []Honeyvent `json:"data"`
96-
Ok bool `json:"ok"`
97-
Message string `json:"message"`
98+
SampleRate100 bool `json:"sample_rate_100,omitempty"`
99+
TelemetrySource string `json:"telemetry_source,omitempty"`
100+
TelemetryType string `json:"telemetry_type,omitempty"`
98101
}
99102

100-
func (e *Honeyvent) AddFeatureField(key string, value interface{}) {
103+
func (e *MetricEvent) AddFeatureField(key string, value interface{}) {
101104
if e.FeatureData == nil {
102105
e.FeatureData = map[string]interface{}{key: value}
103106
return

api/metrics_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ func TestDisableTelemetry(t *testing.T) {
2121

2222
assert.Nil(t, err)
2323

24-
res, err := c.V2.Metrics.Send(api.Honeyvent{})
24+
err = c.V2.Metrics.Send(api.MetricEvent{})
2525

2626
assert.Nil(t, err)
27-
assert.Equal(t, res.Data[0].TraceID, "Telemetry Disabled")
2827
}

cli/cmd/cdk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (c *cliState) Honeyvent(ctx context.Context, in *cdk.HoneyventRequest) (*cd
121121
}
122122

123123
// Send the Honeyvent
124-
c.SendHoneyvent()
124+
c.SendMetricEvent()
125125

126126
return &cdk.Reply{}, nil
127127
}

cli/cmd/cli_state.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type cliState struct {
6161
LwApi *api.Client
6262
JsonF *prettyjson.Formatter
6363
Log *zap.SugaredLogger
64-
Event *api.Honeyvent
64+
Event *api.MetricEvent
6565
Cache *diskv.Diskv
6666
LwComponents *lwcomponent.State
6767

@@ -108,8 +108,8 @@ func NewDefaultState() *cliState {
108108
cdkServerPort: defaultGrpcPort,
109109
}
110110

111-
// initialize honeycomb library and honeyvent
112-
c.InitHoneyvent()
111+
// initialize MetricEvent
112+
c.InitMetricEvent()
113113

114114
return c
115115
}
@@ -135,7 +135,7 @@ func (c *cliState) SetProfile(profile string) error {
135135
// this function verifies parameters and env variables coming from viper
136136
func (c *cliState) LoadState() error {
137137
defer func() {
138-
// update global honeyvent with loaded state
138+
// update global MetricEvent with loaded state
139139
c.Event.Account = c.Account
140140
c.Event.Subaccount = c.Subaccount
141141
c.Event.Profile = c.Profile

cli/cmd/component.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func installComponent(args []string) (err error) {
419419

420420
cli.Event.Component = componentName
421421
cli.Event.Feature = "install_component"
422-
defer cli.SendHoneyvent()
422+
defer cli.SendMetricEvent()
423423

424424
catalog, err := LoadCatalog(componentName, false)
425425
if err != nil {
@@ -896,7 +896,7 @@ func prototypeRunComponentsInstall(_ *cobra.Command, args []string) (err error)
896896

897897
cli.Event.Component = componentName
898898
cli.Event.Feature = "install_component"
899-
defer cli.SendHoneyvent()
899+
defer cli.SendMetricEvent()
900900

901901
cli.StartProgress("Loading components state...")
902902
// @afiune maybe move the state to the cache and fetch if it if has expired

cli/cmd/honeyvent.go renamed to cli/cmd/metricevent.go

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,21 @@ import (
2525
"strings"
2626
"sync"
2727

28-
"github.com/honeycombio/libhoney-go"
2928
"github.com/lacework/go-sdk/v2/api"
3029
"github.com/lacework/go-sdk/v2/lwdomain"
3130
)
3231

3332
var (
34-
// HoneyDataset is the dataset in Honeycomb that we send tracing
33+
// MetricDataset is the dataset in Elastic that we send tracing
3534
// data this variable will be set depending on the environment we
3635
// are running on. During development, we send all events and
3736
// tracing data to a default dataset.
38-
HoneyDataset = "lacework-cli-dev"
37+
MetricDataset = "lacework-cli-dev"
3938
)
4039

4140
const (
4241
// DisableTelemetry is an environment variable that can be used to
43-
// disable telemetry sent to Honeycomb
42+
// disable telemetry sent to Elastic
4443
DisableTelemetry = "LW_TELEMETRY_DISABLE"
4544

4645
// HomebrewInstall is an environment variable that denotes the
@@ -54,13 +53,13 @@ const (
5453
// List of Features
5554
//
5655
// A feature within the Lacework CLI is any functionality that
57-
// can't be traced or tracked by the default event sent to Honeycomb,
56+
// can't be traced or tracked by the default event sent to Elastic,
5857
// it is a behavior that we, Lacework engineers, would like to
5958
// trace and understand its usage and adoption.
6059
//
61-
// By default the Feature field within the Honeyvent is empty,
60+
// By default the Feature field within the MetricEvent is empty,
6261
// define a new feature below and set it before sending a new
63-
// Honeyvent. Additionally, there is a FeatureData field that
62+
// MetricEvent. Additionally, there is a FeatureData field that
6463
// any feature can use to inject any specific information
6564
// related to that feature.
6665
//
@@ -69,7 +68,7 @@ const (
6968
// ```go
7069
// cli.Event.Feature = featPollCtrScan
7170
// cli.Event.AddFeatureField("key", "value")
72-
// cli.SendHoneyvent()
71+
// cli.SendMetricEvent()
7372
// ```
7473
//
7574
// Polling mechanism feature
@@ -91,11 +90,11 @@ const (
9190
featMigrateConfigV2 = "migrate_config_v2"
9291
)
9392

94-
// InitHoneyvent initialize honeycomb library and main Honeyvent, such event
93+
// InitMetricEvent initialize Elastic library and main MetricEvent, such event
9594
// could be modified during a command execution to add extra parameters such
9695
// as error message, feature data, etc.
97-
func (c *cliState) InitHoneyvent() {
98-
c.Event = &api.Honeyvent{
96+
func (c *cliState) InitMetricEvent() {
97+
c.Event = &api.MetricEvent{
9998
Os: runtime.GOOS,
10099
Arch: runtime.GOARCH,
101100
Version: Version,
@@ -106,36 +105,33 @@ func (c *cliState) InitHoneyvent() {
106105
CfgVersion: c.CfgVersion,
107106
TraceID: newID(),
108107
InstallMethod: installMethod(),
109-
Dataset: HoneyDataset,
108+
Dataset: MetricDataset,
110109
}
111110
}
112111

113112
// Wait should be called before finishing the execution of any CLI command,
114-
// it waits for pending workers (a.k.a. honeyvents) to be transmitted
113+
// it waits for pending workers (a.k.a. MetricEvents) to be transmitted
115114
func (c *cliState) Wait() {
116115
// wait for any missing worker
117116
c.workers.Wait()
118117

119-
// flush any pending calls to Honeycomb
120-
libhoney.Close()
121-
122118
// stop gRPC server gracefully
123119
c.Stop()
124120
}
125121

126-
// SendHoneyvent is used throughout the CLI to send Honeyvents, these events
122+
// SendMetricEvent is used throughout the CLI to send metric events, these events
127123
// have tracing data to understand how the commands are being executed, what
128124
// features are used and the overall command flow. This function sends the
129125
// events via goroutines so that we don't block the execution of the main process
130126
//
131127
// NOTE: the CLI will send at least one event per command execution
132-
func (c *cliState) SendHoneyvent() {
128+
func (c *cliState) SendMetricEvent() {
133129
if disabled := os.Getenv(DisableTelemetry); disabled != "" {
134130
return
135131
}
136132

137133
if c.LwApi == nil {
138-
c.Log.Debug("unable to send honeyvent", "error")
134+
c.Log.Debug("unable to send MetricEvent", "error")
139135
return
140136
}
141137

@@ -154,8 +150,7 @@ func (c *cliState) SendHoneyvent() {
154150

155151
// Lacework accounts are NOT case-sensitive but some users configure them
156152
// in uppercase and others in lowercase, therefore we will normalize all
157-
// account to be lowercase so that we don't see different accounts in
158-
// Honeycomb.
153+
// account to be lowercase so that we don't see different accounts in metrics.
159154
c.Event.Account = strings.ToLower(c.Event.Account)
160155

161156
// Detect if the account has the full domain, if so, subtract the account
@@ -166,31 +161,30 @@ func (c *cliState) SendHoneyvent() {
166161
}
167162
}
168163

169-
c.Log.Debugw("new honeyvent", "dataset", HoneyDataset,
164+
c.Log.Debugw("new metric event", "dataset", MetricDataset,
170165
"trace_id", c.Event.TraceID,
171166
"span_id", c.Event.SpanID,
172167
"parent_id", c.Event.ParentID,
173168
"context_id", c.Event.ContextID,
174169
)
175-
honeyvent := libhoney.NewEvent()
176-
_ = honeyvent.Add(c.Event)
177-
honeycombEvent := *c.Event
178-
honeycombEvent.Dataset = c.Event.Dataset
170+
171+
event := *c.Event
172+
event.Dataset = c.Event.Dataset
179173

180174
c.workers.Add(1)
181-
go func(wg *sync.WaitGroup, event *libhoney.Event, honeycombEvent api.Honeyvent) {
175+
go func(wg *sync.WaitGroup, event api.MetricEvent) {
182176
defer wg.Done()
183177

184-
c.Log.Debugw("sending honeyvent", "dataset", HoneyDataset)
178+
c.Log.Debugw("sending MetricEvent", "dataset", MetricDataset)
185179

186-
_, err := c.LwApi.V2.Metrics.Send(honeycombEvent)
180+
err := c.LwApi.V2.Metrics.Send(event)
187181
if err != nil {
188-
c.Log.Debugw("unable to send honeyvent", "error", err)
182+
c.Log.Debugw("unable to send MetricEvent", "error", err)
189183
}
190184

191-
}(&c.workers, honeyvent, honeycombEvent)
185+
}(&c.workers, event)
192186

193-
// after adding a worker to submit a honeyvent, we remove
187+
// after adding a worker to submit a metric event, we remove
194188
// all temporal fields such as feature, feature.data, error
195189
c.Event.DurationMs = 0
196190
c.Event.Error = ""

0 commit comments

Comments
 (0)