Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat (travis) adding travis build #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions moleculer-metrics.coverprofile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mode: atomic
github.com/moleculer-go/moleculer-metrics/prometheus.go:34.44,40.76 4 1
github.com/moleculer-go/moleculer-metrics/prometheus.go:34.50,40.76 4 1
github.com/moleculer-go/moleculer-metrics/prometheus.go:64.2,64.82 1 1
github.com/moleculer-go/moleculer-metrics/prometheus.go:107.2,110.82 2 1
github.com/moleculer-go/moleculer-metrics/prometheus.go:220.2,317.63 1 1
github.com/moleculer-go/moleculer-metrics/prometheus.go:220.2,317.83 1 1
github.com/moleculer-go/moleculer-metrics/prometheus.go:40.76,42.14 2 1
github.com/moleculer-go/moleculer-metrics/prometheus.go:47.3,48.10 2 1
github.com/moleculer-go/moleculer-metrics/prometheus.go:52.3,54.43 2 1
Expand All @@ -25,7 +25,7 @@ github.com/moleculer-go/moleculer-metrics/prometheus.go:166.10,168.5 1 0
github.com/moleculer-go/moleculer-metrics/prometheus.go:184.36,189.4 1 7
github.com/moleculer-go/moleculer-metrics/prometheus.go:198.34,202.4 1 2
github.com/moleculer-go/moleculer-metrics/prometheus.go:211.32,216.4 1 8
github.com/moleculer-go/moleculer-metrics/prometheus.go:317.63,325.4 6 1
github.com/moleculer-go/moleculer-metrics/prometheus.go:317.83,325.4 6 1
github.com/moleculer-go/moleculer-metrics/prometheus.go:330.114,337.20 6 14
github.com/moleculer-go/moleculer-metrics/prometheus.go:371.2,371.12 1 0
github.com/moleculer-go/moleculer-metrics/prometheus.go:338.15,343.16 2 8
Expand Down
14 changes: 7 additions & 7 deletions prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
// * docker-compose up -d
// *
// * Grafana dashboard: http://<docker-ip>:3000
func PrometheusService() moleculer.Service {
func PrometheusService() moleculer.ServiceSchema {

collectors := make(map[string]prometheus.Collector)
metricsCreatedChan := make(chan bool)
Expand Down Expand Up @@ -159,7 +159,7 @@ func PrometheusService() moleculer.Service {

nodesCollector := collectors["moleculer_nodes"].(*prometheus.GaugeVec)
for _, item := range nodes {
node := payload.Create(item)
node := payload.New(item)
var value float64
if node.Get("available").Bool() {
value = 1
Expand Down Expand Up @@ -217,7 +217,7 @@ func PrometheusService() moleculer.Service {

}

return moleculer.Service{
return moleculer.ServiceSchema{
Name: "prometheus",
Settings: map[string]interface{}{
"port": 3030,
Expand Down Expand Up @@ -314,14 +314,14 @@ func PrometheusService() moleculer.Service {
Handler: traceSpanFinished,
},
},
Started: func(service moleculer.Service, logger *log.Entry) {
createMetrics(service.Settings, logger)
Started: func(context moleculer.BrokerContext, service moleculer.ServiceSchema) {
createMetrics(service.Settings, context.Logger())

port := fmt.Sprint(":", service.Settings["port"])
logger.Debug("Prometheus collector service started! port: ", port)
context.Logger().Debug("Prometheus collector service started! port: ", port)
endpoint := service.Settings["endpoint"].(string)
http.Handle(endpoint, promhttp.Handler())
logger.Fatal(http.ListenAndServe(port, nil))
context.Logger().Fatal(http.ListenAndServe(port, nil))
},
}
}
Expand Down
11 changes: 5 additions & 6 deletions prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var _ = Describe("Prometheus", func() {
logLevel := "fatal"
mem := &memory.SharedMemory{}
var bkr, bkr2 *broker.ServiceBroker
musicService := moleculer.Service{
musicService := moleculer.ServiceSchema{
Name: "music",
Actions: []moleculer.Action{
moleculer.Action{
Expand All @@ -83,7 +83,7 @@ var _ = Describe("Prometheus", func() {
},
}
BeforeSuite(func() {
bkr = broker.FromConfig(&moleculer.BrokerConfig{
bkr = broker.New(&moleculer.Config{
Metrics: true,
LogLevel: logLevel,
DiscoverNodeID: func() string { return "Prometheus_Broker" },
Expand All @@ -92,7 +92,7 @@ var _ = Describe("Prometheus", func() {
return &transport
},
})
bkr.AddService(PrometheusService())
bkr.Publish(PrometheusService())
bkr.Start()
time.Sleep(500 * time.Millisecond)
})
Expand All @@ -109,7 +109,7 @@ var _ = Describe("Prometheus", func() {
})

It("Should have updated the metrics after a new services was added", func() {
bkr2 = broker.FromConfig(&moleculer.BrokerConfig{
bkr2 = broker.New(&moleculer.Config{
Metrics: true,
LogLevel: logLevel,
DiscoverNodeID: func() string { return "Client_Broker_1" },
Expand All @@ -118,7 +118,7 @@ var _ = Describe("Prometheus", func() {
return &transport
},
})
bkr2.AddService(musicService)
bkr2.Publish(musicService)
bkr2.Start()
time.Sleep(200 * time.Millisecond)

Expand All @@ -143,7 +143,6 @@ var _ = Describe("Prometheus", func() {
time.Sleep(time.Millisecond * 1000)

results := fetchResults()
//fmt.Println("**************** \n ", results, "\n\n\n-")
Expect(getValue(results, "moleculer_all_req_total")).Should(Equal("24"))
Expect(getValue(results, "moleculer_all_req_duration_ms_count")).Should(Equal("24"))
Expect(getValue(results, "moleculer_all_req_duration_ms_bucket{le=\"10\"}")).Should(Equal("24"))
Expand Down