This repository has been archived by the owner on Aug 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/api: submit service default rates in /v0.4 endpoint (#546)
Submits defaults for services with no environment set in the endpoint response.
- Loading branch information
Showing
10 changed files
with
258 additions
and
127 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
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 |
---|---|---|
@@ -1,36 +1,44 @@ | ||
package sampler | ||
|
||
import ( | ||
"github.com/DataDog/datadog-trace-agent/internal/agent" | ||
) | ||
import "sync" | ||
|
||
const defaultServiceRateKey = "service:,env:" | ||
|
||
type serviceKeyCatalog map[string]Signature | ||
|
||
func byServiceKey(service, env string) string { | ||
return "service:" + service + ",env:" + env | ||
// serviceKeyCatalog reverse-maps service signatures to their generated hashes for | ||
// easy look up. | ||
type serviceKeyCatalog struct { | ||
mu sync.Mutex | ||
lookup map[ServiceSignature]Signature | ||
} | ||
|
||
func newServiceKeyCatalog() serviceKeyCatalog { | ||
return serviceKeyCatalog(make(map[string]Signature)) | ||
// newServiceLookup returns a new serviceKeyCatalog. | ||
func newServiceLookup() *serviceKeyCatalog { | ||
return &serviceKeyCatalog{ | ||
lookup: make(map[ServiceSignature]Signature), | ||
} | ||
} | ||
|
||
func (cat serviceKeyCatalog) register(root *agent.Span, env string, sig Signature) { | ||
map[string]Signature(cat)[byServiceKey(root.Service, env)] = sig | ||
func (cat *serviceKeyCatalog) register(svcSig ServiceSignature) Signature { | ||
hash := svcSig.Hash() | ||
cat.mu.Lock() | ||
cat.lookup[svcSig] = hash | ||
cat.mu.Unlock() | ||
return hash | ||
} | ||
|
||
func (cat serviceKeyCatalog) getRateByService(rates map[Signature]float64, totalScore float64) map[string]float64 { | ||
rbs := make(map[string]float64, len(rates)+1) | ||
for key, sig := range map[string]Signature(cat) { | ||
// ratesByService returns a map of service signatures mapping to the rates identified using | ||
// the signatures. | ||
func (cat serviceKeyCatalog) ratesByService(rates map[Signature]float64, totalScore float64) map[ServiceSignature]float64 { | ||
rbs := make(map[ServiceSignature]float64, len(rates)+1) | ||
defer cat.mu.Unlock() | ||
cat.mu.Lock() | ||
for key, sig := range cat.lookup { | ||
if rate, ok := rates[sig]; ok { | ||
rbs[key] = rate | ||
} else { | ||
// Backend, with its decay mecanism, should automatically remove the entries | ||
// which have such a low value that they don't matter any more. | ||
delete(cat, key) | ||
delete(cat.lookup, key) | ||
} | ||
} | ||
rbs[defaultServiceRateKey] = totalScore | ||
rbs[ServiceSignature{}] = totalScore | ||
return rbs | ||
} |
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.