Telemetry: avoid errors when authorization failed for technical reasons (#9803)
This commit is contained in:
parent
68ec274c00
commit
422922940b
2 changed files with 8 additions and 2 deletions
|
|
@ -17,10 +17,16 @@ var (
|
|||
ExpiresAt time.Time
|
||||
)
|
||||
|
||||
const unavailable = "sponsorship unavailable"
|
||||
|
||||
func IsAuthorized() bool {
|
||||
return len(Subject) > 0
|
||||
}
|
||||
|
||||
func IsAuthorizedForApi() bool {
|
||||
return IsAuthorized() && Subject != unavailable
|
||||
}
|
||||
|
||||
// check and set sponsorship token
|
||||
func ConfigureSponsorship(token string) error {
|
||||
host := util.Getenv("GRPC_URI", cloud.Host)
|
||||
|
|
@ -43,7 +49,7 @@ func ConfigureSponsorship(token string) error {
|
|||
|
||||
if err != nil {
|
||||
if s, ok := status.FromError(err); ok && s.Code() != codes.Unknown {
|
||||
Subject = "sponsorship unavailable"
|
||||
Subject = unavailable
|
||||
err = nil
|
||||
} else {
|
||||
err = fmt.Errorf("sponsortoken: %w", err)
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ var (
|
|||
|
||||
func Enabled() bool {
|
||||
enabled, _ := settings.Bool(enabledSetting)
|
||||
return enabled && sponsor.IsAuthorized() && instanceID != ""
|
||||
return enabled && sponsor.IsAuthorizedForApi() && instanceID != ""
|
||||
}
|
||||
|
||||
func Enable(enable bool) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue