Slide 1

Slide 1 text

メルカリにおける開発環境/QA環境と、 そこで使われるGoのツールについて mercari.go #2 @masudak

Slide 2

Slide 2 text

About me

Slide 3

Slide 3 text

About me HN: @masudak Team: ● 2016/04-: joined as Backend Engineer ● 2016/10-: started as SET(Software engineer in Test) 今回: SETが作った環境・ツールの話

Slide 4

Slide 4 text

Agenda ● 簡単にSETの紹介 ● 作った環境 ● そこで使われているGoの様々なツールの紹 介

Slide 5

Slide 5 text

SET(Software Engineer in Test) ● 2016/10: 創設 ● Mission ○ Improve engineering productivity ○ Encourage quality improvement ● Other companies ○ SDET, SWET, SETI “SETs are developers who write test code and automation as their primary task” https://testing.googleblog.com/2011/04/set-career-pa th.html?m=1 See also: SETチームの設立背景と次世代のSETに向けて

Slide 6

Slide 6 text

SET(Software Engineer in Test) ● Position ○ Backend SET, Frontend SET, Microservices SET, iOS SET and so on ● History ○ Determined to release “UK App” ○ A few env as “Code of Infrastructure” ○ A lot of regression tests

Slide 7

Slide 7 text

SET(Software Engineer in Test) ● Did ○ Local development environment ○ QA environment ○ PR based environments ○ Automate UI Test ○ CI/CD ○ Refactoring

Slide 8

Slide 8 text

Development flow

Slide 9

Slide 9 text

Development flow • PMs create specifications and fix it on Jira • Engineers and designers implement it in “local environment development” • Request it to review of members as a PR • LGTM • QA engineers make “QA” in “QA environment” • PMs approve it • Engineers release it

Slide 10

Slide 10 text

Did

Slide 11

Slide 11 text

Local development environment ● For all engineers and designers ● Prepare docker images ○ Apache, gaurun, widebullet, chocon ● Execute “make init, make start” ● Docker for Mac with docker-compose ● Set IP in local ● And then, access from dev client

Slide 12

Slide 12 text

QA environment of monolith ● Environment for QA engineers ● GCP(GLB, GCE, GCS, GCR) ● Ansible ● Docker ● Web UI ○ set “branch name” and “target” ● Deploy branch environment

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Last year

Slide 15

Slide 15 text

QA env Architecture in US ● Monolith -> Microservices ● PHP -> Go ● Manually deploy with Web UI -> Automatically

Slide 16

Slide 16 text

First

Slide 17

Slide 17 text

QA env Architecture in US

Slide 18

Slide 18 text

QA env Architecture in US ● Template manifest of k8s ● CircleCI: ○ replace the template to PR number ○ apply the template ○ create deployment and service of k8s ● Go proxy ○ get HTTP header from client ○ proxy each service with the header ● Application to delete ○ get webhook when closing PR ○ destroy existing pod

Slide 19

Slide 19 text

Go proxy

Slide 20

Slide 20 text

Go proxy director := func(req *http.Request) { xPrNumber := req.Header.Get("X-QA-PR") apisPort := 3000 req.URL.Scheme = "http" if xPrNumber != "" { req.URL.Host = fmt.Sprintf("api-%s:%d", xPrNumber, apisPort) } else { req.URL.Host = fmt.Sprintf("-api:%d", apisPort) } } rp := &httputil.ReverseProxy{ Director: director, } rp.ServeHTTP(w, req)

Slide 21

Slide 21 text

Second

Slide 22

Slide 22 text

QA environment of microservices ● Pull Request Replication Controller ● 詳しくはこちら ○ https://www.slideshare.net/VishalBanthi a1/kubernetes-controller-for-pull-reques t-based-environment ● k8sのコントローラーを作成 ● reconciliation loop ○ Current State -> Desired State

Slide 23

Slide 23 text

QA environment of microservices ● サービスディスカバリのために事前に Annotationをk8sのサービスに付与 annotation: pr-rc.alpha.example.com/repository: https://github.com/exaple/hello-service ● k8s APIを用いてN秒に一回取得 ● 該当レポジトリへGitHub API経由でアクセス (desired state) ● クラスタ内の情報をk8s API経由で取得 (current state) ● Replicasetをdesiredに近づける(増やす・減 らす)

Slide 24

Slide 24 text

QA environment of microservices ● おかげで、PRごとの環境が自動で作られる ● OSSにもなる予定

Slide 25

Slide 25 text

Third

Slide 26

Slide 26 text

grpc-translator ● gRPC-HTTP変換ツール ● MS間の通信はgRPC ● 何かとRESTで喋りたいときがある ● ex: QAエンジニアがテストデータ入れる ● grpc-gatewayとかあるけど ● protoファイルを編集したくない ● RESTなげたら、gRPC話してほしい

Slide 27

Slide 27 text

grpc-translator ● サービスディスカバリのためにAnnotationをRC に事前に付与 Annotation: translator/proto-service: my.package.MyService ● JSON-RPCでリクエストを受付 ● Annotationをもとにサービス探索 ● GRPC Server Reflection Protocolでサービス の仕様を取得する ● その仕様に合わせてサービスをコールする ● レスポンス ● OSSになるはず!

Slide 28

Slide 28 text

おわりに ● SETは生産性や品質をキーワードに多くの業 務をやってる ● それらの低下はビジネス力の低下 ● Goのプロダクトやツールは至るところで使われ ています!!

Slide 29

Slide 29 text

ご清聴 ありがとうございました