mirror of
https://github.com/coder/coder.git
synced 2025-07-23 21:32:07 +00:00
chore: refactor entitlements to be a safe object to use (#14406)
* chore: refactor entitlements to be passable as an argument Previously, all usage of entitlements requires mutex usage on the api struct directly. This prevents passing the entitlements to a sub package. It also creates the possibility for misuse.
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
package license
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"github.com/coder/coder/v2/coderd/entitlements"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
)
|
||||
|
||||
@@ -15,7 +14,7 @@ var (
|
||||
)
|
||||
|
||||
type MetricsCollector struct {
|
||||
Entitlements atomic.Pointer[codersdk.Entitlements]
|
||||
Entitlements *entitlements.Set
|
||||
}
|
||||
|
||||
var _ prometheus.Collector = new(MetricsCollector)
|
||||
@@ -27,12 +26,7 @@ func (*MetricsCollector) Describe(descCh chan<- *prometheus.Desc) {
|
||||
}
|
||||
|
||||
func (mc *MetricsCollector) Collect(metricsCh chan<- prometheus.Metric) {
|
||||
entitlements := mc.Entitlements.Load()
|
||||
if entitlements == nil || entitlements.Features == nil {
|
||||
return
|
||||
}
|
||||
|
||||
userLimitEntitlement, ok := entitlements.Features[codersdk.FeatureUserLimit]
|
||||
userLimitEntitlement, ok := mc.Entitlements.Feature(codersdk.FeatureUserLimit)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user