Correct multiplexing

This commit is contained in:
9seconds
2019-11-11 14:04:15 +03:00
parent 0ff9a58780
commit 22905b2a25
19 changed files with 445 additions and 436 deletions
+3 -3
View File
@@ -34,8 +34,8 @@ type CrashInterface interface {
Crash()
}
type AntiReplayDetectedInterface interface {
AntiReplayDetected()
type ReplayDetectedInterface interface {
ReplayDetected()
}
type Interface interface {
@@ -46,5 +46,5 @@ type Interface interface {
TelegramConnectedInterface
TelegramDisconnectedInterface
CrashInterface
AntiReplayDetectedInterface
ReplayDetectedInterface
}
+2 -2
View File
@@ -50,8 +50,8 @@ func (m multiStats) Crash() {
}
}
func (m multiStats) AntiReplayDetected() {
func (m multiStats) ReplayDetected() {
for i := range m {
go m[i].AntiReplayDetected()
go m[i].ReplayDetected()
}
}
+8 -8
View File
@@ -18,7 +18,7 @@ type statsPrometheus struct {
telegramConnections *prometheus.GaugeVec
traffic *prometheus.GaugeVec
crashes prometheus.Gauge
antiReplays prometheus.Counter
replayAttacks prometheus.Counter
}
func (s *statsPrometheus) IngressTraffic(traffic int) {
@@ -84,8 +84,8 @@ func (s *statsPrometheus) Crash() {
s.crashes.Inc()
}
func (s *statsPrometheus) AntiReplayDetected() {
s.antiReplays.Inc()
func (s *statsPrometheus) ReplayDetected() {
s.replayAttacks.Inc()
}
func newStatsPrometheus(mux *http.ServeMux) (Interface, error) {
@@ -112,10 +112,10 @@ func newStatsPrometheus(mux *http.ServeMux) (Interface, error) {
Name: "crashes",
Help: "How many crashes happened.",
}),
antiReplays: prometheus.NewCounter(prometheus.CounterOpts{
replayAttacks: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: config.C.StatsNamespace,
Name: "anti_replays",
Help: "How many anti replay attacks were prevented.",
Name: "replay_attacks",
Help: "How many replay attacks were prevented.",
}),
}
@@ -135,8 +135,8 @@ func newStatsPrometheus(mux *http.ServeMux) (Interface, error) {
return nil, fmt.Errorf("cannot register metrics for crashes: %w", err)
}
if err := registry.Register(instance.antiReplays); err != nil {
return nil, fmt.Errorf("cannot register metrics for anti replays: %w", err)
if err := registry.Register(instance.replayAttacks); err != nil {
return nil, fmt.Errorf("cannot register metrics for replays: %w", err)
}
handler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
+2 -2
View File
@@ -79,8 +79,8 @@ func (s *statsStatsd) Crash() {
s.client.Increment("crashes")
}
func (s *statsStatsd) AntiReplayDetected() {
s.client.Increment("anti_replays")
func (s *statsStatsd) ReplayDetected() {
s.client.Increment("replay_attacks")
}
func newStatsStatsd() (Interface, error) {