You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DEVELOPMENT.md
+84Lines changed: 84 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -92,8 +92,92 @@ Use the `npm overrides` mechanism in the `package.json`. Delete the `package-loc
92
92
}
93
93
```
94
94
95
+
## Issue with Grafana, json-source-map and our opennms-js OnmsEnum / toJSON representation
95
96
## opennms-js and json-source-map isJSON issue
96
97
97
98
This is described more fully here: https://github.com/OpenNMS/opennms-js/pull/1118
98
99
99
100
Just note that if `opennms-js` has any model data classes which have a `toJSON` method (which returns a somewhat more human-readable version of the object), it will also have this fix, meaning the object will also have a fake `.replace()` method on it. Should not cause any issues, but just noting it here.
101
+
102
+
More details...
103
+
104
+
This is a bit long-winded, but it was tricky to debug.
105
+
106
+
There is an issue with how Grafana saves and serializes panel data and our `opennms-js` implementation of `OnmsEnum`
107
+
and derived classes.
108
+
109
+
In cases where we are using the Grafana `SegmentAsync` dropdown, which has a `loadOptions` function to
110
+
load nodes (ultimately via `opennms-js` and to our Rest API), we need to make sure that the `loadNodes` prop receives a
111
+
`SelectableValue<T>[]`, e.g. `SelectableValue<PerformanceAttributeItemState>[]`, and
112
+
*not* an `OnmsNode[]`.
113
+
114
+
While `OnmsNode` has an `id` and `label` which `SelectableValue<T>` might be expecting, there's another issue.
115
+
116
+
When you make a change in a query editor, Grafana saves off the panel state.
117
+
Grafana does a `jsonDiff` by serializing the old and new state.
118
+
They use the `json-source-map` npm library to stringify objects (recursively) before diffing.
119
+
120
+
`json-source-map` has a line where if an object has a `toJSON()` function, it uses
121
+
it to stringify the object. It expects `toJSON()` to return a `String`.
122
+
123
+
Our `OnmsEnum`, and derived classes (for example `OnmsManagedType`, used in `OnmsIpInterface.isManaged`,
124
+
used in `OnmsNode.ipInterfaces`), has a `toJSON()` function defined, but it returns
125
+
an object `{ id: this.i, label: this.l }` instead of a `String`.
126
+
127
+
The Grafana code then calls `getDashboardChanges`, `getPanelChanges`:
0 commit comments