add start,end for transfer.index.fullmatch get (#494)

* add start,end with transfer.index.fullmatch get

* bugfix: should cleanup token before destory session when auth.extra.mode.enable
This commit is contained in:
yubo 2021-01-09 14:09:06 +08:00 committed by GitHub
parent 54512491b7
commit b9aacf28e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 15 deletions

View File

@ -1,5 +1,10 @@
package dataobj
import (
"fmt"
"time"
)
type QueryData struct {
Start int64 `json:"start"`
End int64 `json:"end"`
@ -97,10 +102,34 @@ type XcludeResp struct {
}
type IndexByFullTagsRecv struct {
Endpoints []string `json:"endpoints"`
Nids []string `json:"nids"`
Metric string `json:"metric"`
Tagkv []TagPair `json:"tagkv"`
Endpoints []string `json:"endpoints"`
Nids []string `json:"nids"`
Metric string `json:"metric"`
Tagkv []TagPair `json:"tagkv"`
Start int64 `json:"start" description:"inclusive"`
End int64 `json:"end" description:"exclusive"`
StartInclusive time.Time `json:"-"`
EndExclusive time.Time `json:"-"`
}
func (p *IndexByFullTagsRecv) Validate() error {
if p.End == 0 {
p.EndExclusive = time.Now()
} else {
p.EndExclusive = time.Unix(p.End, 0)
}
if p.Start == 0 {
p.StartInclusive = p.EndExclusive.Add(-time.Hour * 25)
} else {
p.StartInclusive = time.Unix(p.Start, 0)
}
if p.StartInclusive.After(p.EndExclusive) {
return fmt.Errorf("start is after end")
}
return nil
}
type IndexByFullTagsResp struct {

View File

@ -237,8 +237,7 @@ func (p *Authenticator) DeleteSession(sid string) error {
if !p.extraMode {
pkgcache.Delete("sid." + s.Sid)
models.SessionDelete(s.Sid)
return nil
return models.SessionDelete(s.Sid)
}
return deleteSession(s)
}
@ -490,10 +489,12 @@ func checkPassword(cf *models.AuthConfig, passwd string) error {
func deleteSession(s *models.Session) error {
pkgcache.Delete("sid." + s.Sid)
models.SessionDelete(s.Sid)
pkgcache.Delete("access-token." + s.AccessToken)
models.TokenDelete(s.AccessToken)
return nil
if err := models.SessionDelete(s.Sid); err != nil {
return err
}
return models.TokenDelete(s.AccessToken)
}
func deleteSessionByToken(t *models.Token) error {

View File

@ -733,9 +733,15 @@ func pwdRulesGet(c *gin.Context) {
}
func sessionDestory(c *gin.Context) (sid string, err error) {
if sid, err = session.Destroy(c.Writer, c.Request); sid != "" {
auth.DeleteSession(sid)
if sid, err = session.GetSid(c.Request); sid == "" {
return
}
if e := auth.DeleteSession(sid); e != nil {
logger.Debugf("auth.deleteSession sid %s err %v", sid, e)
}
session.Destroy(c.Writer, c.Request)
return
}

View File

@ -46,6 +46,10 @@ func Destroy(w http.ResponseWriter, r *http.Request) (string, error) {
return DefaultSession.Destroy(w, r)
}
func GetSid(r *http.Request) (string, error) {
return DefaultSession.GetSid(r)
}
func Get(sid string) (*SessionStore, error) {
return DefaultSession.Get(sid)
}
@ -99,7 +103,7 @@ type Manager struct {
func (p *Manager) Start(w http.ResponseWriter, r *http.Request) (store *SessionStore, err error) {
var sid string
if sid, err = p.getSid(r); err != nil {
if sid, err = p.GetSid(r); err != nil {
return
}
@ -172,7 +176,7 @@ func (p *Manager) All() int {
return p.all()
}
func (p *Manager) getSid(r *http.Request) (sid string, err error) {
func (p *Manager) GetSid(r *http.Request) (sid string, err error) {
var cookie *http.Cookie
cookie, err = r.Cookie(p.config.CookieName)

View File

@ -268,6 +268,11 @@ func (p *Client) QueryIndexByFullTags(inputs []dataobj.IndexByFullTagsRecv) ([]d
var resp dataobj.IndexByFullTagsResp
for i, input := range inputs {
if err := input.Validate(); err != nil {
logger.Errorf("input validate err %s", err)
continue
}
resp = p.queryIndexByFullTags(session, input)
list[i] = resp
count += resp.Count

View File

@ -231,8 +231,8 @@ func (cfg M3dbSection) queryIndexByFullTagsOptions(input dataobj.IndexByFullTags
}
return query, index.QueryOptions{
StartInclusive: indexStartTime(),
EndExclusive: time.Now(),
StartInclusive: input.StartInclusive,
EndExclusive: input.EndExclusive,
SeriesLimit: cfg.SeriesLimit,
DocsLimit: cfg.DocsLimit,
}