Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
feat: zipkin traceid response header
Browse files Browse the repository at this point in the history
from #496
  • Loading branch information
omegabytes authored Nov 7, 2022
1 parent 13d6c20 commit fd32be8
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 3 deletions.
1 change: 1 addition & 0 deletions internal/plugin/schemas/zipkin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ return {
{ connect_timeout = typedefs.timeout { default = 2000 } },
{ send_timeout = typedefs.timeout { default = 5000 } },
{ read_timeout = typedefs.timeout { default = 5000 } },
{ http_response_header_for_traceid = { type = "string", default = nil } },
},
}, },
},
Expand Down
17 changes: 17 additions & 0 deletions internal/server/kong/ws/config/compat/compatibility_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const (
versionsPre270 = "< 2.7.0"
versionsPre280 = "< 2.8.0"
versionsPre300 = "< 3.0.0"
versionsPre310 = "< 3.1.0"
versions300AndAbove = ">= 3.0.0"
)

Expand Down Expand Up @@ -852,6 +853,22 @@ var (
Remove: true,
},
},
{
Metadata: config.ChangeMetadata{
ID: config.ChangeID("P136"),
Severity: config.ChangeSeverityError,
Description: standardPluginFieldsMessage("zipkin",
[]string{"http_response_header_for_traceid"},
"3.1", false),
Resolution: standardUpgradeMessage("3.1"),
},
SemverRange: versionsPre310,
Update: config.ConfigTableUpdates{
Name: "zipkin",
Type: config.Plugin,
RemoveFields: []string{"http_response_header_for_traceid"},
},
},
}
)

Expand Down
7 changes: 5 additions & 2 deletions internal/test/e2e/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,9 @@ var VersionCompatibilityOSSPluginConfigurationTests = []VersionCompatibilityPlug
//
// DP < 3.0:
// - remove 'http_span_name', 'connect_timeout'
// 'send_timeout', 'read_timeout'
// 'send_timeout', 'read_timeout',
// DP < 3.1:
// - remove 'http_response_header_for_traceid'
{
Name: "zipkin",
Config: `{
Expand All @@ -414,7 +416,8 @@ var VersionCompatibilityOSSPluginConfigurationTests = []VersionCompatibilityPlug
"http_span_name": "method_path",
"connect_timeout": 2001,
"send_timeout": 2001,
"read_timeout": 2001
"read_timeout": 2001,
"http_response_header_for_traceid": "X-B3-TraceId"
}`,
FieldUpdateChecks: map[string][]FieldUpdateCheck{
"< 2.7.0": {
Expand Down
82 changes: 81 additions & 1 deletion internal/test/e2e/version_compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func TestVersionCompatibility_PluginFieldUpdates(t *testing.T) {
for _, plugin := range expectedPluginsMap {
var config structpb.Struct
if len(plugin.Config) > 0 {
require.NoError(t, json.ProtoJSONUnmarshal([]byte(plugin.Config), &config))
require.NoError(t, json.ProtoJSONUnmarshal([]byte(plugin.Config), &config), plugin)
}

p := &v1.Plugin{
Expand Down Expand Up @@ -1203,3 +1203,83 @@ func TestTagsVersionCompatibility(t *testing.T) {
})
})
}

// Ensure valid field configuration for DP >= 3.1.
func TestVersionCompatibility_Zipkin310OrNewer(t *testing.T) {
cleanup := run.Koko(t)
defer cleanup()

admin := httpexpect.WithConfig(httpexpect.Config{
BaseURL: "http://localhost:3000",
Reporter: httpexpect.NewRequireReporter(t),
Printers: []httpexpect.Printer{
httpexpect.NewCompactPrinter(t),
},
})

tests := []vcPlugins{
{
config: `{
"local_service_name": "LOCAL_SERVICE_NAME",
"header_type": "ignore",
"http_span_name": "method_path",
"connect_timeout": 2001,
"send_timeout": 2001,
"read_timeout": 2001,
"http_response_header_for_traceid": "X-B3-TraceId"
}`,
expectedConfig: `{
"local_service_name": "LOCAL_SERVICE_NAME",
"header_type": "ignore",
"http_span_name": "method_path",
"connect_timeout": 2001,
"send_timeout": 2001,
"read_timeout": 2001,
"http_response_header_for_traceid": "X-B3-TraceId"
}`,
},
}
expectedConfig := &v1.TestingConfig{
Plugins: make([]*v1.Plugin, 0, len(tests)),
}

for _, test := range tests {
var config structpb.Struct
require.NoError(t, json.ProtoJSONUnmarshal([]byte(test.config), &config))

plugin := &v1.Plugin{
Id: uuid.NewString(),
Name: "zipkin",
Config: &config,
Enabled: wrapperspb.Bool(true),
Protocols: []string{"http", "https"},
}
pluginBytes, err := json.ProtoJSONMarshal(plugin)
require.NoError(t, err)
res := admin.POST("/v1/plugins").WithBytes(pluginBytes).Expect()
res.Status(http.StatusCreated)

var expected structpb.Struct
require.NoError(t, json.ProtoJSONUnmarshal([]byte(test.expectedConfig), &expected))
expectedConfig.Plugins = append(expectedConfig.Plugins, &v1.Plugin{
Id: plugin.Id,
Name: plugin.Name,
Config: &expected,
Enabled: plugin.Enabled,
Protocols: plugin.Protocols,
})
}

dpCleanup := run.KongDP(kong.GetKongConfForShared())
defer dpCleanup()
require.NoError(t, util.WaitForKong(t))
require.NoError(t, util.WaitForKongAdminAPI(t))

kongClient.RunWhenKong(t, ">=3.1.0")

util.WaitFunc(t, func() error {
err := util.EnsureConfig(expectedConfig)
t.Log("plugin validation failed", err)
return err
})
}

0 comments on commit fd32be8

Please sign in to comment.