Skip to content

Commit 356a623

Browse files
committed
Merge remote-tracking branch 'origin/release/6.4' into main
2 parents 5edaaed + b2bab0b commit 356a623

File tree

7 files changed

+40
-8
lines changed

7 files changed

+40
-8
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic
77
Versioning](http://semver.org/spec/v2.0.0.html).
88

9-
## Unreleased
9+
## [6.4.1] - 2021-08-24
1010

1111
### Added
1212
- Added `ignore-already-initialized` configuration flag to the sensu-backend
@@ -48,6 +48,12 @@ the etcd response header is nil.
4848
- Agent events API now accepts metrics event.
4949
- Fixed rare cases where the agent could fail to delete temporary files when
5050
downloading assets.
51+
- Forwards compatibility with newer Sensu backends has been improved. Users can
52+
now create resources with fields that are unknown to Sensu.
53+
54+
### Changed
55+
- API and agent services now log at warn level when the start up, not at info.
56+
- Backend now reports when it is ready to process events at warn level.
5157

5258
## [6.4.0] - 2021-06-23
5359

backend/agentd/agentd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func New(c Config, opts ...Option) (*Agentd, error) {
204204

205205
// Start Agentd.
206206
func (a *Agentd) Start() error {
207-
logger.Info("starting agentd on address: ", a.httpServer.Addr)
207+
logger.Warn("starting agentd on address: ", a.httpServer.Addr)
208208
ln, err := net.Listen("tcp", a.httpServer.Addr)
209209
if err != nil {
210210
return fmt.Errorf("failed to start agentd: %s", err)

backend/apid/apid.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
"github.com/gorilla/mux"
1515
"github.com/prometheus/client_golang/prometheus/promhttp"
16-
"go.etcd.io/etcd/client/v3"
16+
clientv3 "go.etcd.io/etcd/client/v3"
1717

1818
"github.com/sensu/sensu-go/backend/apid/actions"
1919
"github.com/sensu/sensu-go/backend/apid/graphql"
@@ -269,7 +269,7 @@ func notFoundHandler(w http.ResponseWriter, req *http.Request) {
269269

270270
// Start APId.
271271
func (a *APId) Start() error {
272-
logger.Info("starting apid on address: ", a.HTTPServer.Addr)
272+
logger.Warn("starting apid on address: ", a.HTTPServer.Addr)
273273
ln, err := net.Listen("tcp", a.HTTPServer.Addr)
274274
if err != nil {
275275
return fmt.Errorf("failed to start apid: %s", err)

backend/apid/graphql/mutations.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func (r *mutationsImpl) PutWrapped(p schema.MutationPutWrappedFieldResolverParam
4343

4444
// decode given
4545
dec := json.NewDecoder(strings.NewReader(raw))
46-
dec.DisallowUnknownFields()
4746
if err = dec.Decode(&ret); err != nil {
4847
return map[string]interface{}{
4948
"errors": wrapInputErrors("raw", err),

backend/backend.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/prometheus/client_golang/prometheus"
1515
"github.com/spf13/viper"
1616
"go.etcd.io/etcd/client/pkg/v3/transport"
17-
"go.etcd.io/etcd/client/v3"
17+
clientv3 "go.etcd.io/etcd/client/v3"
1818
"golang.org/x/time/rate"
1919
"google.golang.org/grpc"
2020

@@ -523,6 +523,8 @@ func (b *Backend) runOnce() error {
523523
defer errCancel()
524524
eg.Go(errCtx)
525525

526+
logger.Warn("backend is running and ready to accept events")
527+
526528
select {
527529
case err := <-eg.Err():
528530
logger.WithError(err).Error("backend stopped working and is restarting")

cli/resource/parse.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ func Parse(in io.Reader) ([]*types.Wrapper, error) {
5151
}
5252
}
5353
dec := json.NewDecoder(bytes.NewReader(jsonBytes))
54-
dec.DisallowUnknownFields()
54+
dec.DisallowUnknownFields() // this will only warn about top-level keys like spec, api_version
55+
warnDec := json.NewDecoder(bytes.NewReader(jsonBytes))
5556
errCount := 0
5657
for dec.More() {
5758
var w types.Wrapper
@@ -68,6 +69,9 @@ func Parse(in io.Reader) ([]*types.Wrapper, error) {
6869
continue
6970
}
7071

72+
// Warn if there are unknown fields
73+
stripWrapperAndMaybeWarn(warnDec, &w, count)
74+
7175
resources = append(resources, &w)
7276
count++
7377
}
@@ -79,6 +83,28 @@ func Parse(in io.Reader) ([]*types.Wrapper, error) {
7983
return resources, err
8084
}
8185

86+
// warn if there are any unknown fields in the resource. ignores errors because
87+
// they would be caught by the other decoder.
88+
func stripWrapperAndMaybeWarn(dec *json.Decoder, wrapper *types.Wrapper, count int) {
89+
envelope := map[string]*json.RawMessage{}
90+
if err := dec.Decode(&envelope); err != nil {
91+
return
92+
}
93+
msg := envelope["spec"]
94+
if msg == nil {
95+
return
96+
}
97+
resource, err := types.ResolveRaw(wrapper.APIVersion, wrapper.Type)
98+
if err != nil {
99+
return
100+
}
101+
dec = json.NewDecoder(bytes.NewReader(*msg))
102+
dec.DisallowUnknownFields()
103+
if err := dec.Decode(&resource); err != nil {
104+
describeError(count, fmt.Errorf("warning: %s", err))
105+
}
106+
}
107+
82108
// splitResources scans the content of the reader and splits the resources.
83109
// The resources should be separated by a line containing only "---".
84110
// An error will be returned if the data from the reader cannot be read.

types/wrapper.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ func (w *Wrapper) UnmarshalJSON(b []byte) error {
167167
return fmt.Errorf("no spec provided")
168168
}
169169
dec := json.NewDecoder(bytes.NewReader(*wrapper.Value))
170-
dec.DisallowUnknownFields()
171170
if err := dec.Decode(&resource); err != nil {
172171
return err
173172
}

0 commit comments

Comments
 (0)