Skip to content

Commit

Permalink
Release 5.14.1 (#3339)
Browse files Browse the repository at this point in the history
* output yaml separator to file output stream instead of default cmd (#3331)

Signed-off-by: Florian Schwab <[email protected]>

* Fix a panic in wizard bus (#3336)

This commit fixes a "send on closed channel" panic that can crash the backend.

Signed-off-by: Eric Chlebek <[email protected]>

* Add prom gauges for schedulerd (#3338)

* Add prom gauges for schedulerd
* Fix a double-stop bug in the check watcher

Signed-off-by: Eric Chlebek <[email protected]>

* The corev2.AuthProvider interface should embed the Resource int… (#3337)

Signed-off-by: Simon Plourde <[email protected]>

* Add default timeout to bolt.Open (#3322)

Signed-off-by: Simon Plourde <[email protected]>

* Prepare 5.14.1 release

Signed-off-by: Simon Plourde <[email protected]>
  • Loading branch information
Simon Plourde authored Oct 16, 2019
1 parent 49220cb commit 1f6d16b
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 19 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

### Added
- Added the `APIKey` resource and HTTP API support for POST, GET, and DELETE.
- Added sensuctl commands to manage the `APIKey` resource.
- Added support for api keys to be used in api authentication.

## [5.14.1] - 2019-10-16

### Added
- Added prometheus gauges for check schedulers.

### Fixed
- Opening an already open Bolt database should not cause sensu-agent to hang
indefinitely.
- [CLI] Dump multiple types as YAML to a file would print separator STDOUT
instead of specified file
- Fixed a bug where Sensu would crash with a panic due to a send on a closed channel.

## [5.14.0] - 2019-10-08

### Added
Expand Down
10 changes: 7 additions & 3 deletions agent/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"sync"
"time"

"github.com/sensu/lasr"
bolt "go.etcd.io/bbolt"
Expand Down Expand Up @@ -68,12 +69,15 @@ func newQueue(path string) (queue, error) {
return newMemoryQueue(1000), nil
}
if err := os.MkdirAll(path, 0744|os.ModeDir); err != nil {
return nil, fmt.Errorf("error creating api queue: %s", err)
return nil, fmt.Errorf("could not create directory for api queue (%s): %s", path, err)
}
queuePath := filepath.Join(path, "queue.db")
db, err := bolt.Open(queuePath, 0644, nil)
// Create and open the database for the queue. The FileMode given here (0600)
// is only temporary since it will be enforced to 0600 when the queue is
// compacted below by the queue.Compact method
db, err := bolt.Open(queuePath, 0600, &bolt.Options{Timeout: 60 * time.Second})
if err != nil {
return nil, fmt.Errorf("error creating api queue: %s", err)
return nil, fmt.Errorf("could not open api queue (%s): %s", queuePath, err)
}
queue, err := lasr.NewQ(db, "api-buffer")
if err != nil {
Expand Down
12 changes: 2 additions & 10 deletions api/core/v2/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,15 @@ import (

// AuthProvider represents an abstracted authentication provider
type AuthProvider interface {
Resource

// Authenticate attempts to authenticate a user with its username and password
Authenticate(ctx context.Context, username, password string) (*Claims, error)
// Refresh renews the user claims with the provider claims
Refresh(ctx context.Context, claims *Claims) (*Claims, error)

// GetObjectMeta returns the object metadata for the provider
GetObjectMeta() ObjectMeta
// Name returns the provider name (e.g. default)
Name() string
// StorePrefix gives the path prefix to this resource in the store
StorePrefix() string
// Type returns the provider type (e.g. ldap)
Type() string
// URIPath gives the path to the provider
URIPath() string
// Validate checks if the fields in the provider are valid
Validate() error
// SetNamespace sets the namespace of the resource.
SetNamespace(string)
}
10 changes: 10 additions & 0 deletions backend/authentication/providers/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,13 @@ func (p *Provider) claims(username string) corev2.AuthProviderClaims {
func (p *Provider) SetNamespace(namespace string) {
p.Namespace = namespace
}

// RBACName is not implemented
func (p *Provider) RBACName() string {
return ""
}

// SetObjectMeta sets the meta of the resource.
func (p *Provider) SetObjectMeta(meta corev2.ObjectMeta) {
p.ObjectMeta = meta
}
22 changes: 17 additions & 5 deletions backend/messaging/wizard_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,23 @@ func (t *wizardTopic) Send(msg interface{}) {

for _, subscriber := range subscribers {
topicCounter.WithLabelValues(t.id).Set(float64(len(subscriber.Receiver())))
select {
case subscriber.Receiver() <- msg:
case <-t.done:
return
}
safeSend(subscriber.Receiver(), msg, t.done)
}
}

// safeSend can attempt to send to a closed channel without panicking.
// This is only necessary because of a design flaw in wizard bus. Do not
// use this elsewhere.
//
// The topic reads the subscribers and then releases its lock, in Send(). In rare cases,
// cancelling a subscription can lead to a send on a closed channel.
func safeSend(c chan<- interface{}, message interface{}, done chan struct{}) {
defer func() {
_ = recover()
}()
select {
case c <- message:
case <-done:
}
}

Expand Down
2 changes: 2 additions & 0 deletions backend/schedulerd/check_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (c *CheckWatcher) handleWatchEvent(watchEvent store.WatchEventCheckConfig)
if err := c.startScheduler(check); err != nil {
logger.WithError(err).Error("unable to start check scheduler")
}
return
}
if sched.Type() == GetSchedulerType(check) {
logger.Info("restarting scheduler")
Expand All @@ -155,6 +156,7 @@ func (c *CheckWatcher) handleWatchEvent(watchEvent store.WatchEventCheckConfig)
if err := sched.Stop(); err != nil {
logger.WithError(err).Error("error stopping check scheduler")
}
delete(c.items, key)
if err := c.startScheduler(check); err != nil {
logger.WithError(err).Error("unable to start check scheduler")
}
Expand Down
2 changes: 2 additions & 0 deletions backend/schedulerd/cron_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (s *CronScheduler) schedule(timer *CronTimer, executor *CheckExecutor) {

// Start starts the cron scheduler.
func (s *CronScheduler) Start() {
cronCounter.WithLabelValues(s.check.Namespace).Inc()
go s.start()
}

Expand Down Expand Up @@ -97,6 +98,7 @@ func (s *CronScheduler) Interrupt(check *corev2.CheckConfig) {

// Stop stops the cron scheduler.
func (s *CronScheduler) Stop() error {
cronCounter.WithLabelValues(s.check.Namespace).Dec()
logger.Info("stopping cron scheduler")
s.cancel()

Expand Down
2 changes: 2 additions & 0 deletions backend/schedulerd/interval_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (s *IntervalScheduler) schedule(timer CheckTimer, executor *CheckExecutor)

// Start starts the IntervalScheduler.
func (s *IntervalScheduler) Start() {
intervalCounter.WithLabelValues(s.check.Namespace).Inc()
go s.start()
}

Expand Down Expand Up @@ -98,6 +99,7 @@ func (s *IntervalScheduler) Interrupt(check *corev2.CheckConfig) {

// Stop stops the IntervalScheduler
func (s *IntervalScheduler) Stop() error {
intervalCounter.WithLabelValues(s.check.Namespace).Dec()
s.logger.Info("stopping scheduler")
s.cancel()

Expand Down
2 changes: 2 additions & 0 deletions backend/schedulerd/roundrobin_cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func NewRoundRobinCronScheduler(ctx context.Context, store store.Store, bus mess

// Start starts the scheduler.
func (s *RoundRobinCronScheduler) Start() {
rrCronCounter.WithLabelValues(s.check.Namespace).Inc()
go s.start()
}

Expand Down Expand Up @@ -192,6 +193,7 @@ func (s *RoundRobinCronScheduler) Interrupt(check *corev2.CheckConfig) {

// Stop stops the scheduler
func (s *RoundRobinCronScheduler) Stop() error {
rrCronCounter.WithLabelValues(s.check.Namespace).Dec()
s.logger.Info("stopping scheduler")
s.cancel()
return nil
Expand Down
2 changes: 2 additions & 0 deletions backend/schedulerd/roundrobin_interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (s *RoundRobinIntervalScheduler) updateRings() {

// Start starts the round robin interval scheduler.
func (s *RoundRobinIntervalScheduler) Start() {
rrIntervalCounter.WithLabelValues(s.check.Namespace).Inc()
go s.start()
}

Expand Down Expand Up @@ -213,6 +214,7 @@ func (s *RoundRobinIntervalScheduler) Interrupt(check *corev2.CheckConfig) {

// Stop stops the scheduler
func (s *RoundRobinIntervalScheduler) Stop() error {
rrIntervalCounter.WithLabelValues(s.check.Namespace).Dec()
s.logger.Info("stopping scheduler")
s.cancel()
return nil
Expand Down
35 changes: 35 additions & 0 deletions backend/schedulerd/schedulerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/coreos/etcd/clientv3"
"github.com/prometheus/client_golang/prometheus"
corev2 "github.com/sensu/sensu-go/api/core/v2"
"github.com/sensu/sensu-go/backend/messaging"
"github.com/sensu/sensu-go/backend/ringv2"
Expand All @@ -12,6 +13,36 @@ import (
"github.com/sensu/sensu-go/types"
)

var (
intervalCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "sensu_go_interval_schedulers",
Help: "Number of active interval check schedulers on this backend",
},
[]string{"namespace"})

cronCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "sensu_go_cron_schedulers",
Help: "Number of active cron check schedulers on this backend",
},
[]string{"namespace"})

rrIntervalCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "sensu_go_round_robin_interval_schedulers",
Help: "Number of active round robin interval check schedulers on this backend.",
},
[]string{"namespace"})

rrCronCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "sensu_go_round_robin_cron_schedulers",
Help: "Number of active round robin cron check schedulers on this backend.",
},
[]string{"namespace"})
)

// Schedulerd handles scheduling check requests for each check's
// configured interval and publishing to the message bus.
type Schedulerd struct {
Expand Down Expand Up @@ -67,6 +98,10 @@ func New(ctx context.Context, c Config, opts ...Option) (*Schedulerd, error) {

// Start the Scheduler daemon.
func (s *Schedulerd) Start() error {
_ = prometheus.Register(intervalCounter)
_ = prometheus.Register(cronCounter)
_ = prometheus.Register(rrIntervalCounter)
_ = prometheus.Register(rrCronCounter)
return s.checkWatcher.Start()
}

Expand Down
2 changes: 1 addition & 1 deletion cli/commands/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func execute(cli *cli.SensuCli) func(*cobra.Command, []string) error {
err = helpers.PrintWrappedJSONList(resources, w)
case config.FormatYAML:
if i > 0 {
_, _ = fmt.Fprintln(cmd.OutOrStdout(), "---")
_, _ = fmt.Fprintln(w, "---")
}
err = helpers.PrintYAML(resources, w)
default:
Expand Down

0 comments on commit 1f6d16b

Please sign in to comment.