Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TT-9636 Renaming hybrid attributes + adding tests #24

Merged
merged 1 commit into from
Aug 3, 2023
Merged
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
30 changes: 15 additions & 15 deletions semconv/v1.0.0/tykgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const (
// represents the gateway ID
TykGWIDKey = attribute.Key(TykGWPrefix + "id")

// represents if the gateway is hybrid
TykGWHybridKey = attribute.Key(TykGWPrefix + "hybrid")
// represents if the gateway is in a dataplane (edge gateway)
TykGWDataplaneKey = attribute.Key(TykGWPrefix + "dataplane")

// represents the group id of the hybrid gateway
TykHybridGWGroupIDKey = attribute.Key(TykGWPrefix + "group.id")
// represents the group id of the dataplane gateway
TykDataplaneGWGroupIDKey = attribute.Key(TykGWPrefix + "group.id")

// represents the group id of the hybrid gateway
// represents the group id of the dataplane gateway
TykGWSegmentTagsKey = attribute.Key(TykGWPrefix + "tags")
)

Expand All @@ -32,21 +32,21 @@ func TykGWID(id string) trace.Attribute {
return TykGWIDKey.String(id)
}

// TykGWHybrid returns an attribute KeyValue conforming to the
// "tyk.gw.hybrid" semantic convention. It represents if the Tyk Gateway
// is hybrid (slave_options.use_rpc=true).
func TykGWHybrid(isHybrid bool) trace.Attribute {
return TykGWHybridKey.Bool(isHybrid)
// TykGWDataplane returns an attribute KeyValue conforming to the
// "tyk.gw.dataplane" semantic convention. It represents if the Tyk Gateway
// is dataplane (slave_options.use_rpc=true).
func TykGWDataplane(isDataplane bool) trace.Attribute {
return TykGWDataplaneKey.Bool(isDataplane)
}

// TykHybridGWGroupID returns an attribute KeyValue conforming to the
// TykDataplaneGWGroupID returns an attribute KeyValue conforming to the
// "tyk.gw.group.id" semantic convention. It represents the db_app_conf_options.tags
// of the Tyk Gateway. It only populated if the gateway is hybrid.
func TykHybridGWGroupID(groupID string) trace.Attribute {
return TykHybridGWGroupIDKey.String(groupID)
// of the Tyk Gateway. It only populated if the gateway is dataplane.
func TykDataplaneGWGroupID(groupID string) trace.Attribute {
return TykDataplaneGWGroupIDKey.String(groupID)
}

// TykHybridGWGroupID returns an attribute KeyValue conforming to the
// TykGWSegmentTags returns an attribute KeyValue conforming to the
// "tyk.gw.tags" semantic convention. It represents the slave_options.group_id
// of the Tyk Gateway. It only populated if the gateway is segmented.
func TykGWSegmentTags(tags ...string) trace.Attribute {
Expand Down
36 changes: 36 additions & 0 deletions semconv/v1.0.0/tykgateway_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package semconv

import (
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/attribute"
)

func TestTykGWID(t *testing.T) {
id := "gateway-123"
expectedAttribute := attribute.Key(TykGWPrefix + "id").String(id)
actualAttribute := TykGWID(id)
assert.Equal(t, expectedAttribute, actualAttribute, "The attributes should be equal")
}

func TestTykGWDataplane(t *testing.T) {
isDataplane := true
expectedAttribute := attribute.Key(TykGWPrefix + "dataplane").Bool(isDataplane)
actualAttribute := TykGWDataplane(isDataplane)
assert.Equal(t, expectedAttribute, actualAttribute, "The attributes should be equal")
}

func TestTykDataplaneGWGroupID(t *testing.T) {
groupID := "group-123"
expectedAttribute := attribute.Key(TykGWPrefix + "group.id").String(groupID)
actualAttribute := TykDataplaneGWGroupID(groupID)
assert.Equal(t, expectedAttribute, actualAttribute, "The attributes should be equal")
}

func TestTykGWSegmentTags(t *testing.T) {
tags := []string{"tag1", "tag2", "tag3"}
expectedAttribute := attribute.Key(TykGWPrefix + "tags").StringSlice(tags)
actualAttribute := TykGWSegmentTags(tags...)
assert.Equal(t, expectedAttribute, actualAttribute, "The attributes should be equal")
}
Loading