Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lambdas called by their alias are not shown in stats #8

Open
metallkopf opened this issue Feb 16, 2021 · 0 comments
Open

lambdas called by their alias are not shown in stats #8

metallkopf opened this issue Feb 16, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@metallkopf
Copy link

Here a quick hack to fix that.

diff --git a/api/services/lambda_srv.go b/api/services/lambda_srv.go
index 1a4601c..8ffef74 100644
--- a/api/services/lambda_srv.go
+++ b/api/services/lambda_srv.go
@@ -132,7 +132,11 @@ func (srv *lambdaSrv) RenameFile(ctx context.Context, token *api.Token, uid stri
 }
 
 func (srv *lambdaSrv) Stats(ctx context.Context, token *api.Token, uid string, limit int) ([]stats.Record, error) {
-       return srv.tracker.LastByUID(uid, limit)
+       fn, err := srv.cases.Platform().FindByUID(uid)
+       if err != nil {
+               return make([]stats.Record, 0), err
+       }
+       return srv.tracker.LastByUID(uid, fn.Aliases, limit)
 }
 
 func (srv *lambdaSrv) Actions(ctx context.Context, token *api.Token, uid string) ([]string, error) {
diff --git a/stats/impl/memlog/dumped.go b/stats/impl/memlog/dumped.go
index 9ad84fa..557da81 100644
--- a/stats/impl/memlog/dumped.go
+++ b/stats/impl/memlog/dumped.go
@@ -2,6 +2,7 @@ package memlog
 
 import (
        "github.com/reddec/trusted-cgi/stats"
+       "github.com/reddec/trusted-cgi/types"
        "github.com/tinylib/msgp/msgp"
        "io/ioutil"
        "os"
@@ -105,8 +106,8 @@ func (d *dumped) Track(record stats.Record) {
        d.mem.Track(record)
 }
 
-func (d *dumped) LastByUID(uid string, limit int) ([]stats.Record, error) {
-       return d.mem.LastByUID(uid, limit)
+func (d *dumped) LastByUID(uid string, aliases types.JsonStringSet, limit int) ([]stats.Record, error) {
+       return d.mem.LastByUID(uid, aliases, limit)
 }
 
 func (d *dumped) Last(limit int) ([]stats.Record, error) {
diff --git a/stats/impl/memlog/nop.go b/stats/impl/memlog/nop.go
index 211e7a6..3532695 100644
--- a/stats/impl/memlog/nop.go
+++ b/stats/impl/memlog/nop.go
@@ -2,6 +2,7 @@ package memlog
 
 import (
        "github.com/reddec/trusted-cgi/stats"
+       "github.com/reddec/trusted-cgi/types"
 )
 
 func New(depth uint) *statLogger {
@@ -16,7 +17,7 @@ func (s *statLogger) Track(record stats.Record) {
        s.buffer.Add(record)
 }
 
-func (s *statLogger) LastByUID(uid string, limit int) ([]stats.Record, error) {
+func (s *statLogger) LastByUID(uid string, aliases types.JsonStringSet, limit int) ([]stats.Record, error) {
        if limit < 0 {
                return []stats.Record{}, nil
        } else if n := s.buffer.Len(); limit > n {
@@ -27,6 +28,8 @@ func (s *statLogger) LastByUID(uid string, limit int) ([]stats.Record, error) {
        for i := len(clone) - 1; i >= 0 && len(ans) < limit; i-- {
                if clone[i].UID == uid {
                        ans = append(ans, clone[i])
+               } else if _, ok := aliases[clone[i].UID]; ok {
+                       ans = append(ans, clone[i])
                }
        }
        return ans, nil
diff --git a/stats/interface.go b/stats/interface.go
index 92de645..7458bf3 100644
--- a/stats/interface.go
+++ b/stats/interface.go
@@ -25,7 +25,7 @@ type Recorder interface {
 // Reader from tracking systems. All returned records should be sorted from newest to oldest (by insertion moment)
 type Reader interface {
        // Last records for specific app with limits
-       LastByUID(uid string, limit int) ([]Record, error)
+       LastByUID(uid string, aliases types.JsonStringSet, limit int) ([]Record, error)
        // Last all records
        Last(limit int) ([]Record, error)
 }
@reddec reddec added the bug Something isn't working label Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants