Skip to content

Commit

Permalink
Merge pull request #81 from LNOpenMetrics/dev
Browse files Browse the repository at this point in the history
metric_one: fixed restore metric crash
  • Loading branch information
vincenzopalazzo committed Jan 1, 2022
2 parents be3e758 + 663cbe4 commit bbcad93
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 40 deletions.
2 changes: 0 additions & 2 deletions cmd/go-lnmetrics.reporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,5 @@ func loadLastMetricOne() (*metrics.MetricOne, error) {
return nil, err
}
metric.Storage = metricsPlugin.Storage
// TODO: useful to make a migration, this need to be removed in April 2022
metric.Lightning = metricsPlugin.Rpc
return &metric, nil
}
40 changes: 2 additions & 38 deletions internal/plugin/metrics_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,6 @@ type statusChannel struct {
Limits *ChannelLimits `json:"limits"`
}

func (instance *statusChannel) Clone() *statusChannel {
bytes, err := json.Marshal(instance)
if err != nil {
log.GetInstance().Errorf("Unexpected error during cloning status channel: %s", err)
return instance
}

var copy statusChannel
if err := json.Unmarshal(bytes, &copy); err != nil {
log.GetInstance().Errorf("Unexpected error during cloning status channel: %s", err)
return instance
}
return &copy
}

type osInfo struct {
// Operating system name
OS string `json:"os"`
Expand Down Expand Up @@ -224,11 +209,6 @@ type MetricOne struct {

// Storage reference
Storage db.PluginDatabase `json:"-"`

// TODO: this is only to make the migration
// we need to remove when it is not used anymore
// removed in april 2022
Lightning *glightning.Lightning `json:"-"`
}

func (m MetricOne) MarshalJSON() ([]byte, error) {
Expand Down Expand Up @@ -293,24 +273,8 @@ func (instance *MetricOne) UnmarshalJSON(data []byte) error {

instance.ChannelsInfo = make(map[string]*statusChannel, len(t.ChannelsInfo))
for _, channel := range t.ChannelsInfo {
if channel.Direction != "" {
key := strings.Join([]string{channel.ChannelId, channel.Direction}, "_")
instance.ChannelsInfo[key] = channel
} else {
// This is only to migrate from an old payload to a new one
// we have a deprecated period
// TODO: Remove in April 2022
directions, err := instance.getChannelDirections(instance.Lightning, channel.ChannelId)
if err != nil {
log.GetInstance().Errorf("Error: %s", err)
return err
}
for _, direction := range directions {
key := strings.Join([]string{channel.ChannelId, direction}, "_")
channel.Direction = direction
instance.ChannelsInfo[key] = channel.Clone()
}
}
key := strings.Join([]string{channel.ChannelId, channel.Direction}, "_")
instance.ChannelsInfo[key] = channel
}

return nil
Expand Down

0 comments on commit bbcad93

Please sign in to comment.