-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[API] increase api listener limit (#4374)
- Loading branch information
Showing
12 changed files
with
126 additions
and
26 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,48 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
) | ||
|
||
type ( | ||
streamContextKey struct{} | ||
|
||
StreamContext struct { | ||
listenerIDs map[string]struct{} | ||
mutex sync.Mutex | ||
} | ||
) | ||
|
||
func (sc *StreamContext) AddListener(id string) { | ||
sc.mutex.Lock() | ||
defer sc.mutex.Unlock() | ||
sc.listenerIDs[id] = struct{}{} | ||
} | ||
|
||
func (sc *StreamContext) RemoveListener(id string) { | ||
sc.mutex.Lock() | ||
defer sc.mutex.Unlock() | ||
delete(sc.listenerIDs, id) | ||
} | ||
|
||
func (sc *StreamContext) ListenerIDs() []string { | ||
sc.mutex.Lock() | ||
defer sc.mutex.Unlock() | ||
ids := make([]string, 0, len(sc.listenerIDs)) | ||
for id := range sc.listenerIDs { | ||
ids = append(ids, id) | ||
} | ||
return ids | ||
} | ||
|
||
func WithStreamContext(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, streamContextKey{}, &StreamContext{ | ||
listenerIDs: make(map[string]struct{}), | ||
}) | ||
} | ||
|
||
func StreamFromContext(ctx context.Context) (*StreamContext, bool) { | ||
sc, ok := ctx.Value(streamContextKey{}).(*StreamContext) | ||
return sc, ok | ||
} |
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
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,14 @@ | ||
package api | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
var ( | ||
apiLimitMtcs = prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
Name: "iotex_api_limit_metrics", | ||
Help: "api limit metrics.", | ||
}, []string{"limit"}) | ||
) | ||
|
||
func init() { | ||
prometheus.MustRegister(apiLimitMtcs) | ||
} |
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
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