func (m *CentralizedManifest) createDefaultRule(svcRule *xraySvc.SamplingRule) *CentralizedRule {
	clock := &utils.DefaultClock{}
	rand := &utils.DefaultRand{}
	p := &Properties{
		FixedTarget: *svcRule.ReservoirSize,
		Rate:        *svcRule.FixedRate,
	}
	r := &reservoir{
		capacity: *svcRule.ReservoirSize,
	}
	cr := &CentralizedReservoir{
		reservoir: r,
		interval:  defaultInterval,
	}
	csr := &CentralizedRule{
		ruleName:   *svcRule.RuleName,
		reservoir:  cr,
		Properties: p,
		clock:      clock,
		rand:       rand,
	}
	m.mu.Lock()
	defer m.mu.Unlock()
	if d := m.Default; d != nil {
		return d
	}
	m.Default = csr
	m.Index[*svcRule.RuleName] = csr
	return csr
}
createDefaultRule creates a default CentralizedRule and adds it to the manifest.
Panics if svcRule contains nil values for FixedRate and ReservoirSize.
package sampling
import (
	"fmt"
	"sort"
	"strings"
	"sync"
	xraySvc "github.com/aws/aws-sdk-go/service/xray"
	"github.com/aws/aws-xray-sdk-go/utils"
)
const defaultRule = "Default"
const defaultInterval = int64(10)
const manifestTTL = 3600  
type CentralizedManifest struct {
	Default     *CentralizedRule
	Rules       []*CentralizedRule
	Index       map[string]*CentralizedRule
	refreshedAt int64
	clock       utils.Clock
	mu          sync.RWMutex
}
func (m *CentralizedManifest) putRule(svcRule *xraySvc.SamplingRule) (r *CentralizedRule, err error) {
	defer func() {
		if x := recover(); x != nil {
			err = fmt.Errorf("%v", x)
		}
	}()
	name := *svcRule.RuleName
	if name == defaultRule {
		m.mu.RLock()
		r = m.Default
		m.mu.RUnlock()
		if r != nil {
			m.updateDefaultRule(svcRule)
			return
		}
		r = m.createDefaultRule(svcRule)
		return
	}
	m.mu.RLock()
	r, ok := m.Index[name]
	m.mu.RUnlock()
	if !ok {
		r = m.createUserRule(svcRule)
		return
	}
	m.updateUserRule(r, svcRule)
	return
}
func (m *CentralizedManifest) createUserRule(svcRule *xraySvc.SamplingRule) *CentralizedRule {
	clock := &utils.DefaultClock{}
	rand := &utils.DefaultRand{}
	p := &Properties{
		ServiceName: *svcRule.ServiceName,
		HTTPMethod:  *svcRule.HTTPMethod,
		URLPath:     *svcRule.URLPath,
		FixedTarget: *svcRule.ReservoirSize,
		Rate:        *svcRule.FixedRate,
		Host:        *svcRule.Host,
	}
	r := &reservoir{
		capacity: *svcRule.ReservoirSize,
	}
	cr := &CentralizedReservoir{
		reservoir: r,
		interval:  defaultInterval,
	}
	csr := &CentralizedRule{
		ruleName:    *svcRule.RuleName,
		priority:    *svcRule.Priority,
		reservoir:   cr,
		Properties:  p,
		serviceType: *svcRule.ServiceType,
		resourceARN: *svcRule.ResourceARN,
		attributes:  svcRule.Attributes,
		clock:       clock,
		rand:        rand,
	}
	m.mu.Lock()
	defer m.mu.Unlock()
	if r, ok := m.Index[*svcRule.RuleName]; ok {
		return r
	}
	m.Rules = append(m.Rules, csr)
	m.Index[*svcRule.RuleName] = csr
	return csr
}
func (m *CentralizedManifest) updateUserRule(r *CentralizedRule, svcRule *xraySvc.SamplingRule) {
	pr := &Properties{
		ServiceName: *svcRule.ServiceName,
		HTTPMethod:  *svcRule.HTTPMethod,
		URLPath:     *svcRule.URLPath,
		FixedTarget: *svcRule.ReservoirSize,
		Rate:        *svcRule.FixedRate,
		Host:        *svcRule.Host,
	}
	p, c := *svcRule.Priority, *svcRule.ReservoirSize
	r.mu.Lock()
	defer r.mu.Unlock()
	r.Properties = pr
	r.priority = p
	r.reservoir.capacity = c
	r.serviceType = *svcRule.ServiceType
	r.resourceARN = *svcRule.ResourceARN
	r.attributes = svcRule.Attributes
}