feat(backend): fixed issue in start request
This commit is contained in:
parent
354f071fb0
commit
df2ee71bbb
3 changed files with 11 additions and 6 deletions
|
|
@ -168,12 +168,11 @@ func (e *Router) startSessionHandlerWeb(w http.ResponseWriter, r *http.Request)
|
||||||
dice := byte(rand.Intn(100)) // [0, 100)
|
dice := byte(rand.Intn(100)) // [0, 100)
|
||||||
// Use condition rate if it's set
|
// Use condition rate if it's set
|
||||||
if req.Condition != "" {
|
if req.Condition != "" {
|
||||||
rate, err := e.services.Conditions.GetRate(p.ProjectID, req.Condition)
|
rate, err := e.services.Conditions.GetRate(p.ProjectID, req.Condition, int(p.SampleRate))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("can't get condition rate: %s", err)
|
log.Printf("can't get condition rate: %s", err)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("condition rate: %d", rate)
|
p.SampleRate = byte(rate)
|
||||||
p.SampleRate = byte(rate) // why byte?
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Printf("project sample rate: %d", p.SampleRate)
|
log.Printf("project sample rate: %d", p.SampleRate)
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,16 @@ import (
|
||||||
"openreplay/backend/pkg/db/postgres/pool"
|
"openreplay/backend/pkg/db/postgres/pool"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Conditions interface{}
|
type Conditions interface {
|
||||||
|
GetRate(projectID uint32, condition string, def int) (int, error)
|
||||||
|
}
|
||||||
|
|
||||||
type conditionsImpl struct{}
|
type conditionsImpl struct{}
|
||||||
|
|
||||||
|
func (c *conditionsImpl) GetRate(projectID uint32, condition string, def int) (int, error) {
|
||||||
|
return def, nil
|
||||||
|
}
|
||||||
|
|
||||||
func New(db pool.Pool) Conditions {
|
func New(db pool.Pool) Conditions {
|
||||||
return &conditionsImpl{}
|
return &conditionsImpl{}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
type Conditions interface {
|
type Conditions interface {
|
||||||
Get(projectID uint32) (*Response, error)
|
Get(projectID uint32) (*Response, error)
|
||||||
GetRate(projectID uint32, condition string) (int, error)
|
GetRate(projectID uint32, condition string, def int) (int, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type conditionsImpl struct {
|
type conditionsImpl struct {
|
||||||
|
|
@ -108,7 +108,7 @@ func (c *conditionsImpl) Get(projectID uint32) (*Response, error) {
|
||||||
return &Response{Conditions: conditions}, err
|
return &Response{Conditions: conditions}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *conditionsImpl) GetRate(projectID uint32, condition string) (int, error) {
|
func (c *conditionsImpl) GetRate(projectID uint32, condition string, def int) (int, error) {
|
||||||
proj, ok := c.cache[projectID]
|
proj, ok := c.cache[projectID]
|
||||||
if ok {
|
if ok {
|
||||||
rate, ok := proj[condition]
|
rate, ok := proj[condition]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue