Skip to content

Commit

Permalink
change business logik all stats info will be go to the same index
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian simon committed Dec 2, 2019
1 parent 24d8b11 commit 0386c0c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
21 changes: 20 additions & 1 deletion dataResolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strings"
"time"

"github.com/fasibio/funk-server/logger"
Expand Down Expand Up @@ -128,7 +129,16 @@ func (u *DataServiceWebSocket) interpretMessage(messages []Message, logs *zap.Su
Attributes: msg.Attributes,
StaticContent: staticContent,
}, msg.SearchIndex+"_funk-"+getIndexDate(time.Now(), u.rollOverPattern))

case MessageTypeStats:
{
u.Db.AddStats(StatsData{
Timestamp: msg.Time,
Type: string(msg.Type),
Stats: d,
Attributes: msg.Attributes,
StaticContent: staticContent,
}, getStatsIndexName(msg.SearchIndex)+getIndexDate(time.Now(), u.rollOverPattern))
}
default:
{
u.Db.AddStats(StatsData{
Expand All @@ -144,6 +154,15 @@ func (u *DataServiceWebSocket) interpretMessage(messages []Message, logs *zap.Su
}
}

func getStatsIndexName(name string) string {
if strings.Contains(name, "_stats_cumulated") {
return "stats_cumulated_funk-"
} else {
return "stats_funk-"
}

}

func (u *DataServiceWebSocket) messageSubscribeHandler(uuid string, c *websocket.Conn) {
logs := getLoggerWithSubscriptionID(logger.Get(), uuid)
for {
Expand Down
26 changes: 26 additions & 0 deletions dataResolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,29 @@ func TestDataServiceWebSocket_Root(t *testing.T) {
t.Errorf("Want statuscode %v but got %v", 200, res.StatusCode)
}
}

func Test_getStatsIndexName(t *testing.T) {
tests := []struct {
name string
param string
want string
}{
{
name: "given cumulated so want cumulated back",
param: "lalal_stats_cumulated",
want: "stats_cumulated_funk-",
},
{
name: "given not cumulated so want stats_funk- back",
param: "lalal_stats",
want: "stats_funk-",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getStatsIndexName(tt.param); got != tt.want {
t.Errorf("getStatsIndexName() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 0386c0c

Please sign in to comment.