Babelfish 基本试用

测试使用docker 部署

docker-compose文件

注意网络模型选择的host,同时配置了opentracing 服务

version: "3"
services:
  bblfsh:
    image: bblfsh/bblfshd
    privileged: true
    environment:
    - "JAEGER_AGENT_HOST=localhost"
    - "JAEGER_AGENT_PORT=6831"
    - "JAEGER_SAMPLER_TYPE=const"
    - "JAEGER_SAMPLER_PARAM=1"
    network_mode: "host"
    ports:
    - "9432:9432"
    volumes:
    - "/var/lib/bblfshd:/var/lib/bblfshd"
    - "/var/run/docker.sock:/var/run/docker.sock"
  jaeger:
    image: jaegertracing/all-in-one:1.8
    ports:
    - "5775:5775/udp"
    - "6831:6831/udp"
    - "6832:6832/udp"
    - "5778:5778"
    - "16686:16686"
    - "14268:14268"
    - "9411:9411"
 
 

安装驱动

对于语言解析处理的docker 镜像,inside 容器,为了简单,添加的只有golang 的
如果网络比较好的话,可以安装所有的,使用--all参数,或者推荐的 --recommended

 
bblfshctl driver install docker://bblfsh/go-driver:latest

解析 golang 语言

inside 容器,因为按照其他语言的驱动有点慢,所以自己copy 一个golang 代码文件到容器,同时
只安装了简单的golang driver

  • 准备golang 代码
    main.go
 
package main
import "fmt"
func main() {
 fmt.Println("demoapp")
}
 
 

拷贝文件
注意修改为自己的容器id

<wiz_code_mirror>
 
 
 
 
 
docker cp main.go 4116cc1ee650:/opt/
 
 
  • 指定解析
bblfshctl parse /opt/main.go
  • 生成的代码ast 解析
    比较多,保留部分
 
Status: Ok
Elapsed: 1.099302113s
Module {
. Roles: File,Module
. Children: {
. . 0: Expr {
. . . Roles: Expression
. . . StartPosition: {
. . . . Offset: 0
. . . . Line: 1
. . . . Col: 1
. . . }
. . . Properties: {
. . . . internalRole: body
. . . }
. . . Children: {
. . . . 0: Call {
. . . . . Roles: Function,Call,Expression
. . . . . StartPosition: {
. . . . . . Offset: 0
. . . . . . Line: 1
. . . . . . Col: 1
. . . . . }
. . . . . Properties: {
. . . . . . internalRole: value
. . . . . }
. . . . . Children: {
. . . . . . 0: Name {
. . . . . . . Roles: Identifier,Expression,Call,Callee
. . . . . . . TOKEN "print"
. . . . . . . StartPosition: {
. . . . . . . . Offset: 0
. . . . . . . . Line: 1
. . . . . . . . Col: 1
. . . . . . . }
。。。。
 
 
  • opentracing 统计分析
    不同driver 的请求

    golang 解析的请求链路

说明

Babelfish 的功能很强大, 对于我们分析代码是很方便的,同时生产环境,建议的方式是使用client 调用grpc 服务,同时官方也提供了
一个web 的dashboard ,方便我们测试

参考资料

https://doc.bblf.sh/using-babelfish/advanced-usage.html

posted on 2019-01-15 20:21  荣锋亮  阅读(1205)  评论(0编辑  收藏  举报

导航