Skip to content

Commit

Permalink
feat: refactoring metric one to raw local score
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Jan 30, 2023
1 parent a58f9ec commit faff772
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 37 deletions.
4 changes: 2 additions & 2 deletions internal/plugin/cln4go_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func ConfigureCLNPlugin[T MetricsPluginState](state T) (*cln4go.Plugin[T], error
"Disable the usage of proxy in case only for the go-lnmmetrics.reporter", false)
plugin.RegisterNotification("shutdown", &OnShoutdown[T]{})

plugin.RegisterRPCMethod("metric_one", "", "return the metrics calculated by the plugin", NewMetricPlugin[T]())
plugin.RegisterRPCMethod("raw-local-score", "", "return the local reputation raw data collected by the plugin", NewRawLocalScoreRPC[T]())
// FIXME: register the force rpc command only in developer mode
plugin.RegisterRPCMethod("lnmetrics-force-update", "", "trigget the update to the server (caution)", &ForceUpdateRPC[T]{})
plugin.RegisterRPCMethod("lnmetrics-info", "", "return the information regarding the lnmetrics plugin", &LNMetricsInfoRPC[T]{})
Expand Down Expand Up @@ -69,7 +69,7 @@ func (self *LNMetricsInfoRPC[T]) Call(plugin *cln4go.Plugin[T], payload map[stri
goInfo := sysinfo.Go()
resp := info{
Name: "go-lnmetrics.reporter",
Version: "v0.0.5-rc1",
Version: "v0.0.5-rc2",
LangVersion: goInfo.Version,
Architecture: goInfo.Arch,
MaxProcs: goInfo.MaxProcs,
Expand Down
46 changes: 11 additions & 35 deletions internal/plugin/diagnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,30 @@ import (
cln4go "github.com/vincenzopalazzo/cln4go/plugin"
)

type MetricOneRpcMethod[T MetricsPluginState] struct{}
type RawLocalScoreRPC[T MetricsPluginState] struct{}

func NewMetricPlugin[T MetricsPluginState]() *MetricOneRpcMethod[T] {
return &MetricOneRpcMethod[T]{}
func NewRawLocalScoreRPC[T MetricsPluginState]() *RawLocalScoreRPC[T] {
return &RawLocalScoreRPC[T]{}
}

func (instance *MetricOneRpcMethod[T]) Call(plugin *cln4go.Plugin[T], payload map[string]any) (map[string]any, error) {
// FIXME: take variable from the payload.
func (instance *RawLocalScoreRPC[T]) Call(plugin *cln4go.Plugin[T], payload map[string]any) (map[string]any, error) {
metricOne, found := plugin.GetState().GetMetrics()[MetricOneID]
var result map[string]any
if !found {
return nil, fmt.Errorf("Metric with id %d not found", 1)
}

startPeriod, startFound := payload["start"]
//endPeriod, endFound := payload["end"]

if !startFound {
return nil, fmt.Errorf("method argument missing: need to specify the start period")
}

if startPeriod.(string) == "now" {
// FIXME: improve the metric API to include the ToMap call
resultStr, err := json.Marshal(metricOne)
if err != nil {
return nil, err
}

if err != json.Unmarshal(resultStr, &result) {
return nil, err
}
return result, nil
// FIXME: improve the metric API to include the ToMap call
resultStr, err := json.Marshal(metricOne)
if err != nil {
return nil, err
}

if startPeriod.(string) == "last" {
jsonValue, err := plugin.GetState().GetStorage().LoadLastMetricOne()
if err != nil {
return nil, err
}

if err := json.Unmarshal([]byte(*jsonValue), &result); err != nil {
return nil, err
}

return result, nil
if err != json.Unmarshal(resultStr, &result) {
return nil, err
}

return nil, fmt.Errorf("We don't support the filter operation right now")
return result, nil
}

// ForceUpdateRPC enable the force update command
Expand Down

0 comments on commit faff772

Please sign in to comment.