Skip to content

Commit

Permalink
Support versioned URLs (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
grcevski authored Nov 9, 2023
1 parent 842804f commit 0e552f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pkg/internal/transform/route/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func ClusterPath(path string) string {
sFwd := 0

skip := false
skipGrace := true
nSegments := 0
for _, c := range p {
if c == '/' {
Expand All @@ -79,10 +80,15 @@ func ClusterPath(path string) string {
sPos++
sFwd = sPos
skip = false
skipGrace = true
} else if !skip {
p[sFwd] = c
sFwd++
if !isAlpha(c) {
if skipGrace && (sFwd-sPos) == 2 {
skipGrace = false
continue
}
skip = true
}
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/internal/transform/route/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@ func TestURLClustering(t *testing.T) {
err := InitAutoClassifier()
assert.NoError(t, err)
assert.Equal(t, "", ClusterPath(""))
assert.Equal(t, "/users/*/*/*/job/*", ClusterPath("/users/fdklsd/j4elk/23993/job/2"))
assert.Equal(t, "/users/*/j4elk/*/job/*", ClusterPath("/users/fdklsd/j4elk/23993/job/2"))
assert.Equal(t, "*", ClusterPath("123"))
assert.Equal(t, "/*", ClusterPath("/123"))
assert.Equal(t, "*/", ClusterPath("123/"))
assert.Equal(t, "*/*", ClusterPath("123/ljgdflgjf"))
assert.Equal(t, "/*", ClusterPath("/**"))
assert.Equal(t, "/u/*", ClusterPath("/u/2"))
assert.Equal(t, "/v1/products/*", ClusterPath("/v1/products/2"))
assert.Equal(t, "/v1/products/*", ClusterPath("/v1/products/22"))
assert.Equal(t, "/v1/products/*", ClusterPath("/v1/products/22j"))
assert.Equal(t, "/products/*/org/*", ClusterPath("/products/1/org/3"))
assert.Equal(t, "/products//org/*", ClusterPath("/products//org/3"))
assert.Equal(t, "/v1/k6-test-runs/*", ClusterPath("/v1/k6-test-runs/1"))
assert.Equal(t, "/attach", ClusterPath("/attach"))
assert.Equal(t, "/usuarios/*/*/*/trabajo/*", ClusterPath("/usuarios/fdklsd/j4elk/23993/trabajo/2"))
assert.Equal(t, "/Benutzer/*/*/*/Arbeit/*", ClusterPath("/Benutzer/fdklsd/j4elk/23993/Arbeit/2"))
assert.Equal(t, "/utilisateurs/*/*/*/tache/*", ClusterPath("/utilisateurs/fdklsd/j4elk/23993/tache/2"))
assert.Equal(t, "/usuarios/*/j4elk/*/trabajo/*", ClusterPath("/usuarios/fdklsd/j4elk/23993/trabajo/2"))
assert.Equal(t, "/Benutzer/*/j4elk/*/Arbeit/*", ClusterPath("/Benutzer/fdklsd/j4elk/23993/Arbeit/2"))
assert.Equal(t, "/utilisateurs/*/j4elk/*/tache/*", ClusterPath("/utilisateurs/fdklsd/j4elk/23993/tache/2"))
assert.Equal(t, "/products/", ClusterPath("/products/"))
assert.Equal(t, "/user-space/", ClusterPath("/user-space/"))
assert.Equal(t, "/user_space/", ClusterPath("/user_space/"))
Expand Down

0 comments on commit 0e552f2

Please sign in to comment.