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

[mesh] sidecar egress supports routing by request domain #299

Merged
merged 3 commits into from
Oct 14, 2021
Merged

[mesh] sidecar egress supports routing by request domain #299

merged 3 commits into from
Oct 14, 2021

Conversation

benja-wu
Copy link
Contributor

EaseMesh sidecar egress enhancement:

  • Add egress HTTPServer rules for domain routing in DNS-based RPC scenario
  • Domain matching by using exactly matching and regular expression.

@benja-wu benja-wu added the enhancement New feature or request label Oct 13, 2021
Copy link

@megaeasex megaeasex left a comment

Choose a reason for hiding this comment

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

[TASK:easegress-pr-test SUCCESS]megaease/easegress Pull Request 299 Deploy Test Success

@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2021

Codecov Report

Merging #299 (b6ec6a5) into main (12f3379) will increase coverage by 0.22%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #299      +/-   ##
==========================================
+ Coverage   80.23%   80.45%   +0.22%     
==========================================
  Files          53       53              
  Lines        5888     5888              
==========================================
+ Hits         4724     4737      +13     
+ Misses        905      895      -10     
+ Partials      259      256       -3     
Impacted Files Coverage Δ
pkg/object/mqttproxy/topic.go 100.00% <0.00%> (+0.46%) ⬆️
pkg/cluster/cluster.go 50.88% <0.00%> (+2.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bc90a63...b6ec6a5. Read the comment docs.

// vet-services.easemesh.svc.cluster.local
// _zip._tcp.vet-services.easemesh.svc.com
func (egs *EgressServer) buildHostRegex(serviceName string) string {
return fmt.Sprintf("^(|(\\w+\\.)+)%s\\.(\\w+)\\.svc\\..+", serviceName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

propose to not using Sprintf to avoid double escaping which make the regexp hard to read.
and, is the regexp correct?

Suggested change
return fmt.Sprintf("^(|(\\w+\\.)+)%s\\.(\\w+)\\.svc\\..+", serviceName)
return `^(|(\w+\.)+)` + serviceName + `\.(\w+)\.svc\..+`

Copy link
Contributor Author

@benja-wu benja-wu Oct 13, 2021

Choose a reason for hiding this comment

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

I use this program to test the regexp locally, it works.

package main

import (
	"fmt"
	"regexp"
)

func main() {
	hostRE, err := regexp.Compile(`^(|(\w+\.)+)vet-services\.(\w+)\.svc\..+`)
	if err != nil {
		fmt.Printf("gen regexp failed: %v", err)
		return
	}

	pass := func() bool {
		host := "_tcp._zip.vet-services.easemesh.svc.cluster.local"
		if (hostRE.MatchString(host)) != true {
			fmt.Printf("failed at %s\n", host)
			return false
		}

		host = "_zip.vet-services.easemesh.svc.cluster.local"
		if hostRE.Match([]byte(host)) != true {
			fmt.Printf("failed at %s\n", host)
			return false
		}

		host = "_udp.vet-services.easemesh.svc.local"
		if hostRE.Match([]byte(host)) != true {
			fmt.Printf("failed at %s\n", host)
			return false
		}

		host = "vet-services.easemesh.svc.local"
		if hostRE.MatchString(host) != true {
			fmt.Printf("failed at %s\n", host)
			return false
		}

		host = "_tcp._zip.vetservices.easemesh.svc.cluster.local"
		if hostRE.MatchString(host) != false {
			fmt.Printf("failed at %s\n", host)
			return false
		}

		host = "_tcp._zip.vet-services.easemesh.cluster.local"
		if hostRE.MatchString(host) != false {
			fmt.Printf("failed at %s\n", host)
			return false
		}

		host = "_tcp._zip.vet-services.easemesh.svk.cluster.local"
		if hostRE.MatchString(host) != false {
			fmt.Printf("failed at %s\n", host)
			return false
		}

		host = "_tcp._zip.vet-services.easemesh.svc"
		if hostRE.MatchString(host) != false {
			fmt.Printf("failed at %s\n", host)
			return false
		}
		return true
	}()

	if pass {
		fmt.Println("ok")
		return
	}
	fmt.Println("failed")
}

Copy link

@megaeasex megaeasex left a comment

Choose a reason for hiding this comment

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

[TASK:easegress-pr-test SUCCESS]megaease/easegress Pull Request 299 Deploy Test Success

Copy link

@megaeasex megaeasex left a comment

Choose a reason for hiding this comment

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

[TASK:easegress-pr-test SUCCESS]megaease/easegress Pull Request 299 Deploy Test Success

@xxx7xxxx xxx7xxxx merged commit 6cb8de3 into easegress-io:main Oct 14, 2021
@benja-wu benja-wu deleted the sidecar branch October 23, 2021 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants