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

trace system up is up per tenant for cloud #1098

Merged
merged 4 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions server/memphis_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -1886,3 +1886,27 @@ func getStationReplicas(replicas int) int {
func getDefaultReplicas() int {
return 1
}

func updateSystemLiveness() {
stationsHandler := StationsHandler{S: serv}
stations, totalMessages, totalDlsMsgs, err := stationsHandler.GetAllStationsDetails(false, "")
if err != nil {
serv.Warnf("updateSystemLiveness: %v", err.Error())
return
}

producersCount, err := db.CountAllActiveProudcers()
if err != nil {
serv.Warnf("updateSystemLiveness: %v", err.Error())
return
}

consumersCount, err := db.CountAllActiveConsumers()
if err != nil {
serv.Warnf("updateSystemLiveness: %v", err.Error())
return
}

analyticsParams := map[string]interface{}{"total-messages": strconv.Itoa(int(totalMessages)), "total-dls-messages": strconv.Itoa(int(totalDlsMsgs)), "total-stations": strconv.Itoa(len(stations)), "active-producers": strconv.Itoa(int(producersCount)), "active-consumers": strconv.Itoa(int(consumersCount))}
analytics.SendEvent("", "", analyticsParams, "system-is-up")
}
68 changes: 68 additions & 0 deletions server/memphis_handlers_stations.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"errors"
"fmt"
"memphis/analytics"
"memphis/conf"
"memphis/db"
"memphis/models"
"memphis/utils"
Expand All @@ -42,6 +43,21 @@ type StationName struct {
external string
}

type StationsDetailsPerAccount struct {
TotalMessages uint64 `json:"total_messages"`
TotalDlsMessages uint64 `json:"total_dls_messages"`
TotalStations int `json:"total_stations"`
}

type StationsDetailsPerAccountRes struct {
Account string `json:"account"`
TotalMessages string `json:"total_messages"`
TotalDlsMessages string `json:"total_dls_messages"`
TotalStations string `json:"total_stations"`
ActiveProducers int `json:"active_producers"`
ActiveConsumers int `json:"active_consumers"`
}

func (sn StationName) Ext() string {
return sn.external
}
Expand Down Expand Up @@ -659,6 +675,58 @@ func (sh StationsHandler) GetAllStationsDetails(shouldGetTags bool, tenantName s
}
}

func (sh StationsHandler) GetAllStationsDetailsPerTenant(tenantName []string) (map[string]StationsDetailsPerAccount, error) {
shohamroditimemphis marked this conversation as resolved.
Show resolved Hide resolved
var stations []models.ExtendedStation
totalMessages := uint64(0)
StationsDetailsPerTenant := make(map[string]StationsDetailsPerAccount)
for _, tenantName := range tenantName {
if tenantName == "" {
tenantName = conf.MemphisGlobalAccountName
}
totalDlsMessages, err := db.GetTotalDlsMessages(tenantName)
if err != nil {
return map[string]StationsDetailsPerAccount{}, err
}

stations, err = db.GetAllStationsDetailsPerTenant(tenantName)
if err != nil {
return map[string]StationsDetailsPerAccount{}, err
}
if len(stations) == 0 {
res := StationsDetailsPerAccount{
TotalMessages: 0,
TotalDlsMessages: 0,
TotalStations: 0,
}
StationsDetailsPerTenant[tenantName] = res
} else {
acc, err := sh.S.lookupAccount(tenantName)
if err != nil {
return map[string]StationsDetailsPerAccount{}, err
}
accName := acc.Name
allStreamInfo, err := serv.memphisAllStreamsInfo(accName)
if err != nil {
return map[string]StationsDetailsPerAccount{}, err
}
for _, info := range allStreamInfo {
streamName := info.Config.Name
if !strings.Contains(streamName, "$memphis") {
totalMessages += info.State.Msgs
}
}
stationDetailsPerAccountRes := StationsDetailsPerAccount{
TotalMessages: totalMessages,
TotalDlsMessages: totalDlsMessages,
TotalStations: len(stations),
}

StationsDetailsPerTenant[tenantName] = stationDetailsPerAccountRes
}
}
return StationsDetailsPerTenant, nil
}

func (sh StationsHandler) GetStations(c *gin.Context) {
user, err := getUserDetailsFromMiddleware(c)
if err != nil {
Expand Down
26 changes: 0 additions & 26 deletions server/memphis_zombie_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ package server

import (
"encoding/json"
"memphis/analytics"
"memphis/db"
"memphis/models"
"strconv"
"sync"
"time"
)
Expand Down Expand Up @@ -45,30 +43,6 @@ func (srv *Server) removeStaleStations() {
}
}

func updateSystemLiveness() {
stationsHandler := StationsHandler{S: serv}
stations, totalMessages, totalDlsMsgs, err := stationsHandler.GetAllStationsDetails(false, "")
if err != nil {
serv.Warnf("updateSystemLiveness: %v", err.Error())
return
}

producersCount, err := db.CountAllActiveProudcers()
if err != nil {
serv.Warnf("updateSystemLiveness: %v", err.Error())
return
}

consumersCount, err := db.CountAllActiveConsumers()
if err != nil {
serv.Warnf("updateSystemLiveness: %v", err.Error())
return
}

analyticsParams := map[string]interface{}{"total-messages": strconv.Itoa(int(totalMessages)), "total-dls-messages": strconv.Itoa(int(totalDlsMsgs)), "total-stations": strconv.Itoa(len(stations)), "active-producers": strconv.Itoa(int(producersCount)), "active-consumers": strconv.Itoa(int(consumersCount))}
analytics.SendEvent("", "", analyticsParams, "system-is-up")
}

func aggregateClientConnections(s *Server) (map[string]string, error) {
connectionIds := make(map[string]string)
var lock sync.Mutex
Expand Down