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

eskip: remove flowid dependency #3065

Merged
merged 1 commit into from
May 8, 2024
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
31 changes: 15 additions & 16 deletions eskip/eskip.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ package eskip
import (
"errors"
"fmt"
"math/rand"
"net/url"
"regexp"
"strings"
"sync"

log "github.com/sirupsen/logrus"
"github.com/zalando/skipper/filters/flowid"
)

const duplicateHeaderPredicateErrorFmt = "duplicate header predicate: %s"
Expand Down Expand Up @@ -712,29 +712,28 @@ func ParsePredicates(p string) ([]*Predicate, error) {
return ps, nil
}

const randomIdLength = 16

var routeIdRx = regexp.MustCompile(`\W`)
const (
randomIdLength = 16
// does not contain underscore to produce compatible output with previously used flow id generator
alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)

// generate weak random id for a route if
// it doesn't have one.
//
// Deprecated: do not use, generate valid route id that matches [a-zA-Z_] yourself.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecate in the sense of stable?
If so, why do we need to deprecate it?
If we do not plan to delete it, then it's just fine and we do not need to apply the ignore SA1019

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To hint lib users to avoid it.
I'd also delete it in the future as it has strange API contract.

Or do you propose that we keep it or replace with something else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to ask what the plan is, because the PR description nor commit does show what the plan is.
And you talked about deprecated is good because it means it is stable in the last days.

func GenerateIfNeeded(existingId string) string {
if existingId != "" {
return existingId
}

// using this to avoid adding a new dependency.
g, err := flowid.NewStandardGenerator(randomIdLength)
if err != nil {
return existingId
}
id, err := g.Generate()
if err != nil {
return existingId
var sb strings.Builder
sb.WriteString("route")

for i := 0; i < randomIdLength; i++ {
ai := rand.Intn(len(alphabet))
sb.WriteByte(alphabet[ai])
}

// replace characters that are not allowed
// for eskip route ids.
id = routeIdRx.ReplaceAllString(id, "x")
return "route" + id
return sb.String()
}
1 change: 1 addition & 0 deletions etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ func (c *Client) Delete(id string) error {

func (c *Client) UpsertAll(routes []*eskip.Route) error {
for _, r := range routes {
//lint:ignore SA1019 due to backward compatibility
r.Id = eskip.GenerateIfNeeded(r.Id)
err := c.Upsert(r)
if err != nil {
Expand Down
Loading