Skip to content

Commit

Permalink
Merge pull request #30 from OpenLNMetrics/dev
Browse files Browse the repository at this point in the history
Adding a migrate method and adding the logic to convert status channels
  • Loading branch information
vincenzopalazzo authored Aug 13, 2021
2 parents e2a1499 + 9b190a6 commit 79c3135
Show file tree
Hide file tree
Showing 13 changed files with 591 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ jobs:
- name: Check out source code
uses: actions/checkout@v1

- name: Go test
run: make check

- name: Build
run: make build OS=${{ matrix.OS }} ARCH=${{ matrix.ARCH }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fmt:
$(CC) fmt ./...

check:
echo "Nothings yet"
$(CC) test -v ./...

build:
env GOOS=$(OS) GOARCH=$(ARCH) $(CC) build -o $(NAME)-$(OS)-$(ARCH) cmd/go-metrics-reported/main.go
26 changes: 23 additions & 3 deletions cmd/go-metrics-reported/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"errors"
"fmt"
"os"
"strings"

maker "github.com/OpenLNMetrics/go-metrics-reported/init/persistence"
metrics "github.com/OpenLNMetrics/go-metrics-reported/internal/plugin"
"github.com/OpenLNMetrics/go-metrics-reported/pkg/db"
"github.com/OpenLNMetrics/go-metrics-reported/pkg/graphql"
"github.com/OpenLNMetrics/go-metrics-reported/pkg/log"

sysinfo "github.com/elastic/go-sysinfo"
Expand Down Expand Up @@ -53,7 +55,11 @@ func onInit(plugin *glightning.Plugin,
panic(err)
}
db.GetInstance().InitDB(*metricsPath)

err = parseOptionsPlugin(options)
if err != nil {
log.GetInstance().Error(err)
panic(err)
}
//TODO: Load all the metrics in the datatabase that are registered from
// the user
metric, err := loadMetricIfExist(1)
Expand All @@ -75,14 +81,28 @@ func OnRpcCommand(event *glightning.RpcCommandEvent) (*glightning.RpcCommandResp
return event.Continue(), nil
}

// This method include the code to parse the configuration options of the plugin.
func parseOptionsPlugin(options map[string]glightning.Option) error {
urlsAsString, found := options["lnmetrics-urls"]
urls := make([]string, 0)
if found {
urls = strings.FieldsFunc(urlsAsString.GetValue().(string), func(r rune) bool {
return r == ','
})
}
metricsPlugin.Server = graphql.New(urls)
// FIXME: Store the urls on db.
return nil
}

//FIXME: Improve quality of Go style here
func loadMetricIfExist(id int) (metrics.Metric, error) {
metricName, ok := metrics.MetricsSupported[id]
if ok == false {
log.GetInstance().Info(fmt.Sprintf("Metric with id %d not supported", id))
return nil, errors.New(fmt.Sprintf("Metric with id %s not supported", id))
return nil, errors.New(fmt.Sprintf("Metric with id %d not supported", id))
}
log.GetInstance().Info(fmt.Sprintf("Loading metrics with id %s end name", id, metricName))
log.GetInstance().Info(fmt.Sprintf("Loading metrics with id %d end name %s", id, metricName))
metricDb, err := db.GetInstance().GetValue(metricName)
log.GetInstance().Info("value on db us " + metricDb)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ go 1.15

require (
github.com/elastic/go-sysinfo v1.7.0
github.com/kinbiko/jsonassert v1.0.1
github.com/niftynei/glightning v0.8.2
github.com/robfig/cron/v3 v3.0.1
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/syndtr/goleveldb v1.0.0
github.com/zcalusic/sysinfo v0.0.0-20210609180555-aff387a52b3a
github.com/vincenzopalazzo/cpstl/go v0.0.0-20210802220150-6acfbf585502 // indirect
github.com/zcalusic/sysinfo v0.0.0-20210609180555-aff387a52b3a // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/elastic/go-sysinfo v1.7.0 h1:4vVvcfi255+8+TyQ7TYUTEK3A+G8v5FLE+ZKYL1z1Dg=
github.com/elastic/go-sysinfo v1.7.0/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0=
Expand All @@ -13,6 +14,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4=
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak=
github.com/kinbiko/jsonassert v1.0.1 h1:8gdLmUaPWuxk2TzQSofKRqatFH6zwTF6AsUH4bugJYY=
github.com/kinbiko/jsonassert v1.0.1/go.mod h1:QRwBwiAsrcJpjw+L+Q4WS8psLxuUY+HylVZS/4j74TM=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
Expand All @@ -39,6 +42,9 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/vincenzopalazzo/cpstl v0.0.0-20210802212618-10e43ad95b4d h1:G44oroXZ7mPtQpKOZ1xTzesNgQVOVA+5BuE+k7pNZJA=
github.com/vincenzopalazzo/cpstl/go v0.0.0-20210802220150-6acfbf585502 h1:rkiZNZK0dZGhkB6GLD9cX1ZDmT1xHF8zfx3OHREjJ5s=
github.com/vincenzopalazzo/cpstl/go v0.0.0-20210802220150-6acfbf585502/go.mod h1:wh51W+sjnV8DL6VRbp/GY1BZm+2b+tSsUVbnXRHvfP0=
github.com/zcalusic/sysinfo v0.0.0-20210609180555-aff387a52b3a h1:Km41y+ivLvjwZLDJO5/x+NsZrXT+MxrNTLxqs0KnR+I=
github.com/zcalusic/sysinfo v0.0.0-20210609180555-aff387a52b3a/go.mod h1:WGLNaWsjKQ2gXmAHh+MQztgu3FLFAnOFJjFzhpgShCY=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
2 changes: 1 addition & 1 deletion internal/plugin/diagnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (instance *DiagnosticRpcMethod) Call() (jrpc2.Result, error) {
result, err := db.GetInstance().GetValue(key)
if err != nil {
log.GetInstance().Error(fmt.Sprintf("DB error for the key %s", key))
log.GetInstance().Error(fmt.Sprintf("Error is: ", err))
log.GetInstance().Error(fmt.Sprintf("Error is: %s", err))
return nil, errors.New(fmt.Sprintf("DB error for the metric %s with following motivation %s", key, err))
}
var obj interface{}
Expand Down
44 changes: 0 additions & 44 deletions internal/plugin/memory_db.go

This file was deleted.

4 changes: 4 additions & 0 deletions internal/plugin/metric_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ type Metric interface {
UpdateWithMsg(message *Msg, lightning *glightning.Lightning) error
// convert the object into a json
ToJSON() (string, error)
// Migrate to a new version of the metrics, some new version of the plugin
// ca contains some format change and for this reason, this method help
// to migrate the old version to a new version.
Migrate(payload map[string]interface{}) error
}

// Message struct to pass from the plugin to the metric
Expand Down
Loading

0 comments on commit 79c3135

Please sign in to comment.