-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
265 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package entities | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
type ResponseTime struct { | ||
Path string `json:"path,omitempty"` | ||
TimeTakenToLookup int64 `json:"time_taken_to_lookup"` | ||
TimeSpentDecoding int64 `json:"time_spent_decoding"` | ||
TimeSpentWritingBody int64 `json:"time_spent_writing_body"` | ||
} | ||
|
||
type LookupTimes struct { | ||
Mongo map[string]map[string][]ResponseTime `json:"mongo"` | ||
Redis map[string]map[string][]ResponseTime `json:"redis"` | ||
} | ||
|
||
type DebugStatistics struct { | ||
MongoPing int64 `json:"mongo_ping"` | ||
RedisPing int64 `json:"redis_ping"` | ||
LookupTimes LookupTimes `json:"lookup_times"` | ||
ResponseTimes []ResponseTime `json:"response_times"` | ||
Hostname string `json:"hostname"` | ||
} | ||
|
||
var ( | ||
MongoLookupTimes = make(map[string]map[string][]ResponseTime) | ||
RedisLookupTimes = make(map[string]map[string][]ResponseTime) | ||
ResponseTimes []ResponseTime | ||
mutex = &sync.Mutex{} | ||
) | ||
|
||
func AddMongoLookupTime(col, id string, lookup int64, unmarshal int64) { | ||
mutex.Lock() | ||
defer mutex.Unlock() | ||
if _, ok := MongoLookupTimes[col]; ok { | ||
if itemEntry, ok := MongoLookupTimes[col][id]; ok { | ||
itemEntry = append(itemEntry, ResponseTime{ | ||
TimeTakenToLookup: lookup, | ||
TimeSpentDecoding: unmarshal, | ||
TimeSpentWritingBody: 0, | ||
}) | ||
MongoLookupTimes[col][id] = itemEntry | ||
} else { | ||
MongoLookupTimes[col][id] = []ResponseTime{ | ||
{ | ||
TimeTakenToLookup: lookup, | ||
TimeSpentDecoding: unmarshal, | ||
TimeSpentWritingBody: 0, | ||
}, | ||
} | ||
} | ||
} else { | ||
MongoLookupTimes[col] = map[string][]ResponseTime{ | ||
id: { | ||
{ | ||
TimeTakenToLookup: lookup, | ||
TimeSpentDecoding: unmarshal, | ||
TimeSpentWritingBody: 0, | ||
}, | ||
}, | ||
} | ||
} | ||
} | ||
|
||
func AddRedisLookupTime(col, id string, lookup int64, unmarshal int64) { | ||
mutex.Lock() | ||
defer mutex.Unlock() | ||
if _, ok := RedisLookupTimes[col]; ok { | ||
if itemEntry, ok := RedisLookupTimes[col][id]; ok { | ||
itemEntry = append(itemEntry, ResponseTime{ | ||
TimeTakenToLookup: lookup, | ||
TimeSpentDecoding: unmarshal, | ||
TimeSpentWritingBody: -1, | ||
}) | ||
RedisLookupTimes[col][id] = itemEntry | ||
} else { | ||
RedisLookupTimes[col][id] = []ResponseTime{ | ||
{ | ||
TimeTakenToLookup: lookup, | ||
TimeSpentDecoding: unmarshal, | ||
TimeSpentWritingBody: -1, | ||
}, | ||
} | ||
} | ||
} else { | ||
RedisLookupTimes[col] = map[string][]ResponseTime{ | ||
id: { | ||
{ | ||
TimeTakenToLookup: lookup, | ||
TimeSpentDecoding: unmarshal, | ||
TimeSpentWritingBody: -1, | ||
}, | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.