Skip to content

Commit

Permalink
Merge pull request #37 from nats-io/monitoring-metrics
Browse files Browse the repository at this point in the history
Add monitoring port by default and metrics example
  • Loading branch information
wallyqs authored Mar 22, 2019
2 parents 9bdd9ea + dc91d5e commit ca4e4f1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
43 changes: 43 additions & 0 deletions deploy/examples/example-stan-cluster-metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
apiVersion: "streaming.nats.io/v1alpha1"
kind: "NatsStreamingCluster"
metadata:
name: "example-stan"
spec:
# Number of nodes in the cluster
size: 3

# NATS Streaming Server image to use, by default
# the operator will use a stable version
#
image: "nats-streaming:0.12.2"

# Service to which NATS Streaming Cluster nodes will connect.
#
natsSvc: "example-nats"

config:
debug: true
trace: true
raftLogging: true

template:
metadata:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "7777"
spec:
containers:

# Need to list the first container for the server, the operator
# will fill in the rest of the parameters.
- name: "stan"

# Define the sidecar container and the paths that should be polled.
- name: "metrics"
image: "synadia/prometheus-nats-exporter:0.2.0"
args: ["-varz", "-channelz", "-serverz", "-DV", "http://localhost:8222"]
ports:
- name: "metrics"
containerPort: 7777
protocol: TCP
9 changes: 6 additions & 3 deletions internal/operator/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import "time"

const (
// Version is the version of the NATS Streaming Operator.
Version = "0.2.0"
Version = "0.3.0"

// DefaultNATSStreamingImage is the default image
// of NATS Streaming that will be used, meant to be
// the latest release available.
DefaultNATSStreamingImage = "nats-streaming:0.11.2"
DefaultNATSStreamingImage = "nats-streaming:0.12.2"

// DefaultNATSStreamingClusterSize is the default size
// for the cluster. Clustering is done via Raft so
Expand All @@ -31,4 +31,7 @@ const (

// ResyncPeriod is how often the operator will be checking the resources.
ResyncPeriod = 5 * time.Second

// MonitoringPort is the port for the server monitoring endpoint.
MonitoringPort = 8222
)
1 change: 1 addition & 0 deletions internal/operator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ func stanContainerCmd(o *stanv1alpha1.NatsStreamingCluster, pod *k8scorev1.Pod)
"/nats-streaming-server",
"-cluster_id", o.Name,
"-nats_server", fmt.Sprintf("nats://%s:4222", o.Spec.NatsService),
"-m", fmt.Sprintf("%d", MonitoringPort),
}

var storeArgs []string
Expand Down
7 changes: 6 additions & 1 deletion test/operator/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ func TestCreateClusterWithDebugFlags(t *testing.T) {
if !strings.Contains(s, expectedFlag) {
return fmt.Errorf("Does not contain %s flag", expectedFlag)
}

expectedFlag = "-m"
if !strings.Contains(s, expectedFlag) {
return fmt.Errorf("Does not contain %s flag", expectedFlag)
}
}

got := len(result.Items)
Expand Down Expand Up @@ -315,7 +320,7 @@ func TestCreateWithCustomStoreDirTemplate(t *testing.T) {
}
for _, item := range result.Items {
got := strings.Join(item.Spec.Containers[0].Command, " ")
expected := `/nats-streaming-server -cluster_id stan-cluster-custom-store-dir-test -nats_server nats://example-nats:4222 -store file --cluster_node_id="stan-cluster-custom-store-dir-test-1" -dir /my-store-dir/stan-cluster-custom-store-dir-test-1`
expected := `/nats-streaming-server -cluster_id stan-cluster-custom-store-dir-test -nats_server nats://example-nats:4222 -m 8222 -store file --cluster_node_id="stan-cluster-custom-store-dir-test-1" -dir /my-store-dir/stan-cluster-custom-store-dir-test-1`
if got != expected {
return fmt.Errorf("Expected %s, got: %s", expected, got)
}
Expand Down

0 comments on commit ca4e4f1

Please sign in to comment.