mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-29 13:49:28 +08:00

* MF-166 - Add lora-adapter service (#416) * MF-166 - Add lora-adapter service Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix NATS connexion and use credentials with gRPC Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Forward lora msgs to nats Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add make cmd and docker-compose Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Define lora conf as private Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename funcs fix nats conn Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Update README and fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rm NATS sub Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * MF-166 - Add lora-adapter service (#461) * MF-166 - Add lora-adapter service Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix NATS connexion and use credentials with gRPC Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Forward lora msgs to nats Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add make cmd and docker-compose Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Define lora conf as private Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename funcs fix nats conn Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Update README and fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rm NATS sub Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix lora server topic and logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix HTTP port Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * NOISSUE - Add event sourcing client to LoRa adapter (#471) * Add event sourcing client to LoRa adapter Signed-off-by: Aleksandar Novaković <anovakovic01@gmail.com> * Update redis version in docker compose and update env vars Signed-off-by: Aleksandar Novaković <anovakovic01@gmail.com> * Add ES subscription to main LoRa function Signed-off-by: Aleksandar Novaković <anovakovic01@gmail.com> * Add new env vars to readme file of LoRa adapter Signed-off-by: Aleksandar Novaković <anovakovic01@gmail.com> * Add message acknowledgement to LoRa adapter Signed-off-by: Aleksandar Novaković <anovakovic01@gmail.com> * Add handling of empty values to event sourcing client (#474) Signed-off-by: Aleksandar Novaković <anovakovic01@gmail.com> * Add routemap and handle event sourcing Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix eventStore decoding Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Mv docker-compose in docker/addons Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix routemap and logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Update Gopkg.toml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix route map and typos Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Update README Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
96 lines
2.7 KiB
Go
96 lines
2.7 KiB
Go
//
|
|
// Copyright (c) 2018
|
|
// Mainflux
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package api
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/go-kit/kit/metrics"
|
|
"github.com/mainflux/mainflux/lora"
|
|
)
|
|
|
|
var _ lora.Service = (*metricsMiddleware)(nil)
|
|
|
|
type metricsMiddleware struct {
|
|
counter metrics.Counter
|
|
latency metrics.Histogram
|
|
svc lora.Service
|
|
}
|
|
|
|
// MetricsMiddleware instruments core service by tracking request count and latency.
|
|
func MetricsMiddleware(svc lora.Service, counter metrics.Counter, latency metrics.Histogram) lora.Service {
|
|
return &metricsMiddleware{
|
|
counter: counter,
|
|
latency: latency,
|
|
svc: svc,
|
|
}
|
|
}
|
|
|
|
func (mm *metricsMiddleware) CreateThing(mfxDevID string, loraDevEUI string) error {
|
|
defer func(begin time.Time) {
|
|
mm.counter.With("method", "create_thing").Add(1)
|
|
mm.latency.With("method", "create_thing").Observe(time.Since(begin).Seconds())
|
|
}(time.Now())
|
|
|
|
return mm.svc.CreateThing(mfxDevID, loraDevEUI)
|
|
}
|
|
|
|
func (mm *metricsMiddleware) UpdateThing(mfxDevID string, loraDevEUI string) error {
|
|
defer func(begin time.Time) {
|
|
mm.counter.With("method", "update_thing").Add(1)
|
|
mm.latency.With("method", "update_thing").Observe(time.Since(begin).Seconds())
|
|
}(time.Now())
|
|
|
|
return mm.svc.UpdateThing(mfxDevID, loraDevEUI)
|
|
}
|
|
|
|
func (mm *metricsMiddleware) RemoveThing(mfxDevID string) error {
|
|
defer func(begin time.Time) {
|
|
mm.counter.With("method", "remove_thing").Add(1)
|
|
mm.latency.With("method", "remove_thing").Observe(time.Since(begin).Seconds())
|
|
}(time.Now())
|
|
|
|
return mm.svc.RemoveThing(mfxDevID)
|
|
}
|
|
|
|
func (mm *metricsMiddleware) CreateChannel(mfxChanID string, loraApp string) error {
|
|
defer func(begin time.Time) {
|
|
mm.counter.With("method", "create_channel").Add(1)
|
|
mm.latency.With("method", "create_channel").Observe(time.Since(begin).Seconds())
|
|
}(time.Now())
|
|
|
|
return mm.svc.CreateChannel(mfxChanID, loraApp)
|
|
}
|
|
|
|
func (mm *metricsMiddleware) UpdateChannel(mfxChanID string, loraApp string) error {
|
|
defer func(begin time.Time) {
|
|
mm.counter.With("method", "update_channel").Add(1)
|
|
mm.latency.With("method", "update_channel").Observe(time.Since(begin).Seconds())
|
|
}(time.Now())
|
|
|
|
return mm.svc.UpdateChannel(mfxChanID, loraApp)
|
|
}
|
|
|
|
func (mm *metricsMiddleware) RemoveChannel(mfxChanID string) error {
|
|
defer func(begin time.Time) {
|
|
mm.counter.With("method", "remove_channel").Add(1)
|
|
mm.latency.With("method", "remove_channel").Observe(time.Since(begin).Seconds())
|
|
}(time.Now())
|
|
|
|
return mm.svc.RemoveChannel(mfxChanID)
|
|
}
|
|
|
|
func (mm *metricsMiddleware) Publish(m lora.Message) error {
|
|
defer func(begin time.Time) {
|
|
mm.counter.With("method", "message_router").Add(1)
|
|
mm.latency.With("method", "message_router").Observe(time.Since(begin).Seconds())
|
|
}(time.Now())
|
|
|
|
return mm.svc.Publish(m)
|
|
}
|