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:
Yuri Tseretyan
2023-12-11 15:40:31 -05:00
committed by GitHub
parent f69516bf47
commit bf8be46e6f
7 changed files with 284 additions and 6 deletions

View File

@@ -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 {