-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kuma-cp: add a Monitoring Assignment Discovery Service (MADS) server (#…
…531) * kuma-cp: add a Monitoring Assignment Discovery Service (MADS) server * code review: address feedback from code review
- Loading branch information
Showing
15 changed files
with
642 additions
and
57 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
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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package mads | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
"go.uber.org/multierr" | ||
|
||
"github.com/Kong/kuma/pkg/config" | ||
) | ||
|
||
func DefaultMonitoringAssignmentServerConfig() *MonitoringAssignmentServerConfig { | ||
return &MonitoringAssignmentServerConfig{ | ||
GrpcPort: 5676, | ||
AssignmentRefreshInterval: 1 * time.Second, | ||
} | ||
} | ||
|
||
// Monitoring Assignment Discovery Service (MADS) server configuration. | ||
type MonitoringAssignmentServerConfig struct { | ||
// Port of a gRPC server that serves Monitoring Assignment Discovery Service (MADS). | ||
GrpcPort uint32 `yaml:"grpcPort" envconfig:"kuma_monitoring_assignment_server_grpc_port"` | ||
|
||
// Interval for re-generating monitoring assignments for clients connected to the Control Plane. | ||
AssignmentRefreshInterval time.Duration `yaml:"assignmentRefreshInterval" envconfig:"kuma_monitoring_assignment_server_assignment_refresh_interval"` | ||
} | ||
|
||
var _ config.Config = &MonitoringAssignmentServerConfig{} | ||
|
||
func (c *MonitoringAssignmentServerConfig) Sanitize() { | ||
} | ||
|
||
func (c *MonitoringAssignmentServerConfig) Validate() (errs error) { | ||
if 65535 < c.GrpcPort { | ||
errs = multierr.Append(errs, errors.Errorf(".GrpcPort must be in the range [0, 65535]")) | ||
} | ||
if c.AssignmentRefreshInterval <= 0 { | ||
return errors.New(".AssignmentRefreshInterval must be positive") | ||
} | ||
return | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package generator | ||
|
||
import ( | ||
mesh_core "github.com/Kong/kuma/pkg/core/resources/apis/mesh" | ||
"github.com/Kong/kuma/pkg/core/resources/model" | ||
) | ||
|
||
type Context struct { | ||
Meshes []*mesh_core.MeshResource | ||
Dataplanes []*mesh_core.DataplaneResource | ||
} | ||
|
||
type ResourceGenerator interface { | ||
Generate(Context) ([]*model.Resource, error) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package reconcile | ||
|
||
import ( | ||
envoy_core "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" | ||
|
||
util_xds "github.com/Kong/kuma/pkg/util/xds" | ||
) | ||
|
||
// Reconciler re-computes configuration for a given node. | ||
type Reconciler interface { | ||
Reconcile(*envoy_core.Node) error | ||
} | ||
|
||
// Generates a snapshot of xDS resources for a given node. | ||
type SnapshotGenerator interface { | ||
GenerateSnapshot(*envoy_core.Node) (util_xds.Snapshot, error) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package reconcile | ||
|
||
import ( | ||
envoy_core "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" | ||
envoy_cache "github.com/envoyproxy/go-control-plane/pkg/cache" | ||
|
||
util_xds "github.com/Kong/kuma/pkg/util/xds" | ||
) | ||
|
||
func NewReconciler(hasher envoy_cache.NodeHash, cache util_xds.SnapshotCache, | ||
generator SnapshotGenerator, versioner util_xds.SnapshotVersioner) Reconciler { | ||
return &reconciler{ | ||
hasher: hasher, | ||
cache: cache, | ||
generator: generator, | ||
versioner: versioner, | ||
} | ||
} | ||
|
||
type reconciler struct { | ||
hasher envoy_cache.NodeHash | ||
cache util_xds.SnapshotCache | ||
generator SnapshotGenerator | ||
versioner util_xds.SnapshotVersioner | ||
} | ||
|
||
func (r *reconciler) Reconcile(node *envoy_core.Node) error { | ||
new, err := r.generator.GenerateSnapshot(node) | ||
if err != nil { | ||
return err | ||
} | ||
if err := new.Consistent(); err != nil { | ||
return err | ||
} | ||
id := r.hasher.ID(node) | ||
old, _ := r.cache.GetSnapshot(id) | ||
new = r.versioner.Version(new, old) | ||
return r.cache.SetSnapshot(id, new) | ||
} |
Oops, something went wrong.