Skip to content

Commit

Permalink
feat: upgrade to libhoney-go 1.21.0 to support classic ingest keys (#208
Browse files Browse the repository at this point in the history
)

## Which problem is this PR solving?

We've recently updated[ libhoney-go to support classic ingest
keys](https://github.com/honeycombio/libhoney-go/releases/tag/v1.21.0).
This updates the version of libhoney-go to use the new, updated
`IsClassic` check.


## Short description of the changes

- updates libhoney-go to v1.21.0
- updates all existing `isClassic` checks to use the `Config.IsClassic`
check instead
- adds some extra test cases for ingest keys
  • Loading branch information
cewkrupa authored Feb 29, 2024
1 parent 3514cf5 commit 1e862a1
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 28 deletions.
4 changes: 2 additions & 2 deletions cmd_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ a URL pointing to the generated trace in Honeycomb to STDOUT.`,
providerInfo(*ciProvider, ev)

ev.Add(map[string]interface{}{
"service_name": ifClassic(cfg.APIKey, "build", cfg.Dataset),
"service.name": ifClassic(cfg.APIKey, "build", cfg.Dataset),
"service_name": ifClassic(cfg, "build", cfg.Dataset),
"service.name": ifClassic(cfg, "build", cfg.Dataset),
"command_name": "build",
"trace.span_id": traceID,
"name": "build " + traceID,
Expand Down
4 changes: 2 additions & 2 deletions cmd_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ will be launched via "bash -c" using "exec". The shell can be changed with the
ev.Add(map[string]interface{}{
"trace.parent_id": stepID,
"trace.span_id": spanID,
"service_name": ifClassic(cfg.APIKey, "cmd", cfg.Dataset),
"service.name": ifClassic(cfg.APIKey, "cmd", cfg.Dataset),
"service_name": ifClassic(cfg, "cmd", cfg.Dataset),
"service.name": ifClassic(cfg, "cmd", cfg.Dataset),
"command_name": "cmd",
"name": name,
"duration_ms": dur / time.Millisecond,
Expand Down
2 changes: 1 addition & 1 deletion cmd_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The buildevents executable creates Honeycomb events and tracing information
about your Continuous Integration builds.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
quiet, _ := cmd.Flags().GetBool("quiet")
if isClassic(cfg.APIKey) {
if cfg.IsClassic() {
// if we're in classic mode, we want to behave the same as we always have
if cfg.Dataset == "" {
cfg.Dataset = "buildevents"
Expand Down
4 changes: 2 additions & 2 deletions cmd_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ most closely maps to a single job. It should be run at the end of the step.`,
ev.Add(map[string]interface{}{
"trace.parent_id": traceID,
"trace.span_id": stepID,
"service_name": ifClassic(cfg.APIKey, "step", cfg.Dataset),
"service.name": ifClassic(cfg.APIKey, "step", cfg.Dataset),
"service_name": ifClassic(cfg, "step", cfg.Dataset),
"service.name": ifClassic(cfg, "step", cfg.Dataset),
"command_name": "step",
"name": name,
"duration_ms": time.Since(startTime) / time.Millisecond,
Expand Down
6 changes: 3 additions & 3 deletions cmd_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ build with the appropriate timers.`,
}

ev.Add(map[string]interface{}{
"service_name": ifClassic(cfg.APIKey, "watch", cfg.Dataset),
"service.name": ifClassic(cfg.APIKey, "watch", cfg.Dataset),
"service_name": ifClassic(cfg, "watch", cfg.Dataset),
"service.name": ifClassic(cfg, "watch", cfg.Dataset),
"command_name": "watch",
"trace.span_id": traceID,
"name": ifClassic(cfg.APIKey, "watch "+traceID, "watch"),
"name": ifClassic(cfg, "watch "+traceID, "watch"),
"status": status,
"duration_ms": endTime.Sub(startTime) / time.Millisecond,
"source": "buildevents",
Expand Down
13 changes: 4 additions & 9 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ func buildURL(cfg *libhoney.Config, traceID string, ts int64) (string, error) {
if err != nil {
return "", fmt.Errorf("unable to infer UI host: %s", uiHost)
}

pathSegments := []string{team}
if !isClassic(cfg.APIKey) {
if !cfg.IsClassic() {
pathSegments = append(pathSegments, "environments", environment)
}
pathSegments = append(pathSegments, "datasets", slugify(cfg.Dataset), "trace")
Expand All @@ -223,14 +224,8 @@ func buildURL(cfg *libhoney.Config, traceID string, ts int64) (string, error) {
return u.String(), nil
}

// classic keys are always 32 bytes, non-classic are less than that
// classic keys are also hex but that doesn't matter here
func isClassic(key string) bool {
return len(key) == 32
}

func ifClassic(key, classicVal, elseVal string) string {
if isClassic(key) {
func ifClassic(cfg *libhoney.Config, classicVal, elseVal string) string {
if cfg.IsClassic() {
return classicVal
}
return elseVal
Expand Down
14 changes: 6 additions & 8 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ import (
"github.com/stretchr/testify/assert"
)

const (
apiKey = ""
classicAPIKey = ""
)

func TestBuildUrl(t *testing.T) {
testCases := []struct {
Name string
APIKey string
Classic bool
expectedUrl string
}{
{Name: "classic", APIKey: "lcYrFflRUR6rHbIifwqhfGRUR6rHbIic", expectedUrl: "test_team/datasets/test_dataset/trace"},
{Name: "non-classic", APIKey: "lcYrFflRUR6rHbIifwqhfG", expectedUrl: "test_team/environments/test_env/datasets/test_dataset/trace"},
{Name: "classic", Classic: true, APIKey: "25f7d47575430a8fafea5b7d70a6af09", expectedUrl: "test_team/datasets/test_dataset/trace"},
{Name: "classic ingest key", Classic: true, APIKey: "hcaic_1234567890123456789012345678901234567890123456789012345678", expectedUrl: "test_team/datasets/test_dataset/trace"},
{Name: "non classic v2 configuration key", Classic: false, APIKey: "lcYrFflRUR6rHbIifwqhfG", expectedUrl: "test_team/environments/test_env/datasets/test_dataset/trace"},
{Name: "non classic ingest key", Classic: false, APIKey: "hcxik_01hqk4k20cjeh63wca8vva5stw70nft6m5n8wr8f5mjx3762s8269j50wc", expectedUrl: "test_team/environments/test_env/datasets/test_dataset/trace"},
}

for _, tc := range testCases {
Expand All @@ -33,7 +31,7 @@ func TestBuildUrl(t *testing.T) {
assert.Equal(t, "/1/auth", r.URL.Path)
assert.Equal(t, []string{tc.APIKey}, r.Header["X-Honeycomb-Team"])

if isClassic(tc.APIKey) {
if tc.Classic {
w.Write([]byte(`{"team":{"slug":"test_team"}}`))
} else {
w.Write([]byte(`{"team":{"slug":"test_team"},"environment":{"slug":"test_env"}}`))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.15

require (
github.com/honeycombio/beeline-go v1.14.0
github.com/honeycombio/libhoney-go v1.20.0
github.com/honeycombio/libhoney-go v1.21.0
github.com/jszwedko/go-circleci v0.3.0
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515
github.com/spf13/cobra v1.8.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,8 @@ github.com/honeycombio/beeline-go v1.14.0 h1:m146oWmngzG6SGGezOCyoYzL3v3A0AVqRS9
github.com/honeycombio/beeline-go v1.14.0/go.mod h1:RODJ4yaVJjNhQ5eUvi2ZnpY/C074lwD6JI9rYNZfhxg=
github.com/honeycombio/libhoney-go v1.20.0 h1:PL54R0P9vxIyb28H3twbLb+DCqQlJdMQM55VZg1abKA=
github.com/honeycombio/libhoney-go v1.20.0/go.mod h1:RIaurCpfg5NDWSEV8t3QLcda9dUAiVNyWeHRAaSpN90=
github.com/honeycombio/libhoney-go v1.21.0 h1:uiiSfUipFSrmBucKTrwD9Bm4K60kY98p0hVLjtSLseM=
github.com/honeycombio/libhoney-go v1.21.0/go.mod h1:RIaurCpfg5NDWSEV8t3QLcda9dUAiVNyWeHRAaSpN90=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down

0 comments on commit 1e862a1

Please sign in to comment.