Git Product home page Git Product logo

sharingan's Issues

又是一个半成品

滴滴内部员工来吐槽下,难用的一批,响应也很不及时,为了开源而开源的产物

不太理解为什么要改造源代码来传递id?

关于上下游流量inbound/outbound的对应匹配:
这应该是框架做的事情,框架应该维护一个traceid,跟着流量在全链路传播

关于工作委托:
在业务层,应该通过context来传递信息吧,而不是修改源码,把数据存在源码未导出的结构体.

请问使用一个context来传递相关的threadlocal信息有什么局限吗?

goroutine中的redis回放无法捕捉到发起的请求

测试代码
`package main

import (
"github.com/didi/sharingan"
"database/sql"
"github.com/garyburd/redigo/redis"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
_ "github.com/go-sql-driver/mysql"
"log"
"time"
)
var (
SqlDB *sql.DB // mysql连接
RedisConn redis.Conn // redis连接
err error
)

func init() {
SqlDB, err = sql.Open("mysql", "root:my-secret-pw@tcp(192.168.174.134:3306)/meng")
if err != nil {
log.Println("初始化mysql连接失败.", err)
} else {
SqlDB.SetConnMaxLifetime(100 * time.Second) //最大连接周期,超过时间的连接就close
SqlDB.SetMaxOpenConns(100) //设置最大连接数
SqlDB.SetMaxIdleConns(16) //设置闲置连接数
log.Println("初始化mysql连接成功", SqlDB.Stats())
}

RedisConn, err = redis.Dial("tcp", "192.168.174.134:6379")
if err != nil {
	log.Println("Connect to redis error", err)
} else {
	log.Println("初始化redis连接成功")
}

}
func SetTaskRouter() *gin.Engine {
router := gin.Default()
api := router.Group("/api")
{
api.POST("/book",ShanT)
}
return router
}

func main(){
r := SetTaskRouter()
r.Use(cors.Default())
r.Run(":8090")
}

var msg chan string

func init() {
msg = make(chan string)
}

type Book struct {
BookName string db:"name" json:"name"
BookAuthor string db:"author" json:"author"
}

func ShanT(c *gin.Context) {
book := Book{}
c.ShouldBindJSON(&book)
if book.BookName == "" || book.BookAuthor == "" {
c.JSON(500,"需要用户信息")
}
// 写mysql
InsertMysql(book)
// 查询mysql
mbook,err := GetMysqlBookByAuthor(book.BookAuthor)
if err != nil {
log.Println("从mysql查询失败,停止查询")
} else {
log.Println("mysql中查询到的book",mbook)
// 读写redis
go Redis(mbook,sharingan.GetCurrentGoRoutineID())
// 从channel中读取数据
m := <- msg
c.JSON(200,m)
}

}

func InsertMysql(book Book) {
result,err := SqlDB.Exec("insert INTO book(name,author) values (?,?)",book.BookName,book.BookAuthor)
if err != nil {
log.Println("插入myql失败",err)
} else {
num,_ := result.RowsAffected()
log.Println("插入mysql成功,影响行数",num)
}
}

func GetMysqlBookByAuthor(author string) (Book,error){
book := new(Book)
row := SqlDB.QueryRow("select * from book where author=?",author)
//row.scan中的字段必须是按照数据库存入字段的顺序,否则报错
if err :=row.Scan(&book.BookName,&book.BookAuthor); err != nil{
log.Println("从mysql查询失败",err)
return *book,err
} else {
return *book,nil
}
}

func Redis(book Book,delegatedID int64) {
sharingan.SetDelegatedFromGoRoutineID(delegatedID)
defer sharingan.SetDelegatedFromGoRoutineID(0)
_, err = RedisConn.Do("SET", book.BookName,book.BookAuthor)
if err != nil {
log.Println("redis set failed:", err)
}
author, err := redis.String(RedisConn.Do("GET", book.BookName))
if err != nil {
log.Println("redis get failed:", err)
} else {
log.Println("Get mykey: %v \n", author)
}
msg <- author

}
可以连接mysql,但是redis连接异常[GIN-debug] Listening and serving HTTP on :8090
2020/05/22 19:48:44 插入mysql成功,影响行数 1
2020/05/22 19:48:44 mysql中查询到的book {b b}
2020/05/22 19:48:44 redis set failed: EOF
2020/05/22 19:48:44 redis get failed: write tcp 127.0.0.1:45722->127.0.0.1:3515: use of closed network connection
[GIN] 2020/05/22 - 19:48:44 | 200 | 0s | 127.0.0.1 | POST "/api/book"
2020/05/22 19:48:39 插入mysql成功,影响行数 1
2020/05/22 19:48:39 mysql中查询到的book {a a}
2020/05/22 19:48:39 redis set failed: write tcp 127.0.0.1:45722->127.0.0.1:3515: use of closed network connection
2020/05/22 19:48:39 redis get failed: write tcp 127.0.0.1:45722->127.0.0.1:3515: use of closed network connection
`
回放页面显示miss

写轮眼可以录制HTTPS流量吗?

使用过Goreplay,无法直接录制443端口的HTTPS请求。目前的方式是用nginx做流量镜像转发到其他端口,再录制新端口的请求。
请问写轮眼可以直接录制HTTPS流量,而不需要更改反向代理节点配置的方案吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.