servicetracer

package module
v0.0.0-...-01684e9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2020 License: MIT Imports: 25 Imported by: 0

README

go-service-tracer

Visualize the dependencies between Microservices of gRPC methods implemented in Go

Installation

go get github.com/goccy/go-service-tracer/cmd/go-service-tracer

Usage

Consider visualizing the dependencies between microservices A and B.

Microservice A

The repository is developed at github.com/organization/service-a . The main package, which is used to start the server, is located under cmd/a . In order to allow other services to call the API of Microservice A, the proto files maintain at github.com/organization/proto . proto files are located in service-a/v1 directory in github.com/organization/proto ( github.com/organization/proto/service-a/v1 ) .

Microservice B

The repository is developed at github.com/organization/service-b . The main package, which is used to start the server, is located under cmd/b . In order to allow other services to call the API of Microservice B, the proto files maintain at github.com/organization/proto . proto files are located in service-b/v1 directory in github.com/organization/proto ( github.com/organization/proto/service-b/v1 ) .

Getting Started

Write service definition

Write sevice definition to the trace.yaml .

auth:
  token:
    env: GITHUB_TOKEN
services:
  - name: serviceA
    repo: github.com/organization/service-a
    entry: cmd/a
    proto:
      repo: github.com/organization/proto
      path:
        - service-a/v1
  - name: serviceB
    repo: github.com/organization/service-b
    entry: cmd/b
    proto:
      repo: github.com/organization/proto
      path:
        - service-b/v1

auth.token.env parameter available access to private repository. At this example set token to access to private repository as GITHUB_TOKEN .

Run go-service-tracer

Install go-service-tracer and run the following command .

go-service-tracer -c trace.yaml

On success, trace.html is generated in the current directory.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneRepository

func CloneRepository(cfg *Config) error

func CreateCacheDir

func CreateCacheDir() error

func FileURL

func FileURL(service *Service, file string) string

func ProtoRepoRoot

func ProtoRepoRoot(service *Service) string

func RepoRoot

func RepoRoot(service *Service) string

func ServiceMapFile

func ServiceMapFile(service *Service) string

func SubPath

func SubPath(service *Service, file string) string

Types

type AnalyzedMethod

type AnalyzedMethod struct {
	SourceURL string
	Methods   []*Method
}

type Analyzer

type Analyzer struct {
	// contains filtered or unexported fields
}

func NewAnalyzer

func NewAnalyzer(cfg *Config) *Analyzer

func (*Analyzer) Analyze

func (a *Analyzer) Analyze(service *Service) (MethodMap, error)

type Auth

type Auth struct {
	Token Token `yaml:"token"`
}

type Config

type Config struct {
	Auth     Auth       `yaml:"auth"`
	Services []*Service `yaml:"services"`
	Output   string     `yaml:"-"`
}

func LoadConfig

func LoadConfig(opt *Option) (*Config, error)

func (*Config) AuthToken

func (c *Config) AuthToken() string

func (*Config) ServiceNameByGeneratedPath

func (c *Config) ServiceNameByGeneratedPath(path string) (string, error)

type Method

type Method struct {
	Pkg           string `yaml:"pkg"`
	GeneratedPath string `yaml:"generated_path"`
	Service       string `yaml:"service"`
	Name          string `yaml:"name"`
	InputType     string `yaml:"input_type"`
	OutputType    string `yaml:"output_type"`
}

func ParseProto

func ParseProto(serviceName, path string) ([]*Method, error)

func (*Method) GeneratedPathToRepo

func (m *Method) GeneratedPathToRepo() string

func (*Method) MangledName

func (m *Method) MangledName() string

type MethodMap

type MethodMap map[string]*AnalyzedMethod

type Option

type Option struct {
	Config string `description:"specify config path" short:"c" long:"config" required:"true"`
	Output string `description:"specify output name" short:"o" long:"output" default:"trace"`
}

type Proto

type Proto struct {
	Repo string   `yaml:"repo"`
	Path []string `yaml:"path"`
}

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

func NewRenderer

func NewRenderer(cfg *Config) *Renderer

func (*Renderer) Render

func (r *Renderer) Render(methodMap MethodMap) error

type Service

type Service struct {
	Name  string `yaml:"name"`
	Repo  string `yaml:"repo"`
	Entry string `yaml:"entry"`
	Proto Proto  `yaml:"proto"`
	// contains filtered or unexported fields
}

func (*Service) Entries

func (s *Service) Entries() ([]string, error)

func (*Service) MethodNameMap

func (s *Service) MethodNameMap() (map[string][]*Method, error)

func (*Service) Methods

func (s *Service) Methods() ([]*Method, error)

func (*Service) ProtoPaths

func (s *Service) ProtoPaths() []string

func (*Service) ProtoRepoName

func (s *Service) ProtoRepoName() string

func (*Service) RepoName

func (s *Service) RepoName() string

type ServiceTracer

type ServiceTracer struct {
	// contains filtered or unexported fields
}

func New

func New(cfg *Config) *ServiceTracer

func (*ServiceTracer) Run

func (t *ServiceTracer) Run() error

type Token

type Token struct {
	Env string `yaml:"env"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL