mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
SSE: Add utility methods for HysteresisCommand (#79157)
* add GetCommandsFromPipeline * refactor method GetCommandType to func GetExpressionCommandType * add function to create fingerprint frames * add function to determine whether raw query represents a hysteresis command and a function to patch it with loaded metrics
This commit is contained in:
@@ -246,6 +246,41 @@ func TestServicebuildPipeLine(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCommandsFromPipeline(t *testing.T) {
|
||||
pipeline := DataPipeline{
|
||||
&MLNode{},
|
||||
&DSNode{},
|
||||
&CMDNode{
|
||||
baseNode: baseNode{},
|
||||
CMDType: 0,
|
||||
Command: &ReduceCommand{},
|
||||
},
|
||||
&CMDNode{
|
||||
baseNode: baseNode{},
|
||||
CMDType: 0,
|
||||
Command: &ReduceCommand{},
|
||||
},
|
||||
&CMDNode{
|
||||
baseNode: baseNode{},
|
||||
CMDType: 0,
|
||||
Command: &HysteresisCommand{},
|
||||
},
|
||||
}
|
||||
t.Run("should find command that exists", func(t *testing.T) {
|
||||
cmds := GetCommandsFromPipeline[*HysteresisCommand](pipeline)
|
||||
require.Len(t, cmds, 1)
|
||||
require.Equal(t, pipeline[4].(*CMDNode).Command, cmds[0])
|
||||
})
|
||||
t.Run("should find all commands that exist", func(t *testing.T) {
|
||||
cmds := GetCommandsFromPipeline[*ReduceCommand](pipeline)
|
||||
require.Len(t, cmds, 2)
|
||||
})
|
||||
t.Run("should not find all command that does not exist", func(t *testing.T) {
|
||||
cmds := GetCommandsFromPipeline[*MathCommand](pipeline)
|
||||
require.Len(t, cmds, 0)
|
||||
})
|
||||
}
|
||||
|
||||
func getRefIDOrder(nodes []Node) []string {
|
||||
ids := make([]string, 0, len(nodes))
|
||||
for _, n := range nodes {
|
||||
|
||||
Reference in New Issue
Block a user