Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(engine): upgrade ES lib #7088

Merged
merged 8 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions contrib/grpcplugins/action/plugin-archive/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ module github.com/ovh/cds/contrib/grpcplugins/action/archive

replace github.com/ovh/cds => ../../../../

go 1.22
go 1.22.1

toolchain go1.22.6

require (
github.com/golang/protobuf v1.5.3
github.com/mholt/archiver/v3 v3.5.1
github.com/ovh/cds v0.0.0-00010101000000-000000000000
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions contrib/grpcplugins/action/plugin-archive/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/ovh/cds/contrib/grpcplugins/action/artifactoryreleasebundlecreate

go 1.22
go 1.22.1

toolchain go1.22.6

replace github.com/ovh/cds => ../../../../

Expand All @@ -13,7 +15,7 @@ require (
github.com/ovh/cds v0.0.0-00010101000000-000000000000
github.com/pkg/errors v0.9.1
github.com/rockbears/yaml v0.4.0
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
)

require (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/ovh/cds/contrib/grpcplugins/action/artifactoryreleasebundlecreate

go 1.22
go 1.22.1

toolchain go1.22.6

replace github.com/ovh/cds => ../../../../

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
Expand Down
4 changes: 3 additions & 1 deletion contrib/grpcplugins/action/plugin-tmpl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ module github.com/ovh/cds/contrib/grpcplugins/action/tmpl

replace github.com/ovh/cds => ../../../../

go 1.22
go 1.22.1

toolchain go1.22.6

require (
github.com/golang/protobuf v1.5.3
Expand Down
4 changes: 2 additions & 2 deletions contrib/grpcplugins/action/plugin-tmpl/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/ovh/cds/contrib/integrations/artifactory/artifactory-build-info-plugin

go 1.22
go 1.22.1

toolchain go1.22.6

replace github.com/ovh/cds => ../../../../

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/ovh/cds/contrib/integrations/artifactory/artifactory-download-artifact-plugin

go 1.22
go 1.22.1

toolchain go1.22.6

replace github.com/ovh/cds => ../../../../

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/ovh/cds/contrib/integrations/artifactory/artifactory-promote-plugin

go 1.22
go 1.22.1

toolchain go1.22.6

replace github.com/ovh/cds => ../../../../

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/ovh/cds/contrib/integrations/artifactory/artifactory-release-plugin

go 1.22
go 1.22.1

toolchain go1.22.6

replace github.com/ovh/cds => ../../../../

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/ovh/cds/contrib/integrations/artifactory/artifactory-upload-artifact-plugin

go 1.22
go 1.22.1

toolchain go1.22.6

replace github.com/ovh/cds => ../../../../

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
Expand Down
2 changes: 1 addition & 1 deletion engine/elasticsearch/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Test_consumeKafka(t *testing.T) {

mockESClient := mock_elasticsearch.NewMockESClient(ctrl)
s.esClient = mockESClient
mockESClient.EXPECT().IndexDoc(gomock.Any(), "IndexJobSummary", gomock.Any(), gomock.Any(), gomock.Any()).MinTimes(1)
mockESClient.EXPECT().IndexDocWithoutType(gomock.Any(), "IndexJobSummary", gomock.Any(), gomock.Any()).MinTimes(1)

cfg := test.LoadTestingConf(t, sdk.TypeElasticsearch)
if cfg["broker"] == "" {
Expand Down
23 changes: 13 additions & 10 deletions engine/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"time"

"github.com/gorilla/mux"
"github.com/olivere/elastic/v7"
"github.com/opensearch-project/opensearch-go/v4"
"github.com/opensearch-project/opensearch-go/v4/opensearchapi"
"github.com/rockbears/log"

"github.com/ovh/cds/engine/api"
Expand Down Expand Up @@ -99,11 +100,9 @@ func (s *Service) Serve(c context.Context) error {

//Gracefully shutdown the http server
go func() {
select {
case <-ctx.Done():
log.Info(ctx, "ElasticSearch> Shutdown HTTP Server")
_ = server.Shutdown(ctx)
}
<-ctx.Done()
log.Info(ctx, "ElasticSearch> Shutdown HTTP Server")
_ = server.Shutdown(ctx)
}()

if s.Cfg.EventBus.JobSummaryKafka.BrokerAddresses != "" {
Expand All @@ -122,10 +121,14 @@ func (s *Service) Serve(c context.Context) error {
}

func (s *Service) initClient() (ESClient, error) {
x, err := elastic.NewClient(
elastic.SetURL(s.Cfg.ElasticSearch.URL),
elastic.SetBasicAuth(s.Cfg.ElasticSearch.Username, s.Cfg.ElasticSearch.Password),
elastic.SetSniff(false),
x, err := opensearchapi.NewClient(
opensearchapi.Config{
Client: opensearch.Config{
Addresses: []string{s.Cfg.ElasticSearch.URL},
Username: s.Cfg.ElasticSearch.Username,
Password: s.Cfg.ElasticSearch.Password,
},
},
)
if err != nil {
return nil, sdk.WithStack(err)
Expand Down
56 changes: 33 additions & 23 deletions engine/elasticsearch/elasticsearch_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"fmt"
"net/http"
"strconv"
"strings"

"github.com/olivere/elastic/v7"
"github.com/defensestation/osquery"
"github.com/rockbears/log"

"github.com/ovh/cds/engine/service"
Expand All @@ -24,18 +25,23 @@ func (s *Service) getEventsHandler() service.Handler {
return sdk.WrapError(err, "Unable to read body")
}

boolQuery := elastic.NewBoolQuery()
boolQuery.Must(elastic.NewQueryStringQuery("type_event:sdk.EventRunWorkflow"))
var conditions []osquery.Mappable
conditions = append(conditions, osquery.Term("type_event", "sdk.EventRunWorkflow"))

for _, p := range filters.Filter.Projects {
for _, w := range p.WorkflowNames {
boolQuery.Must(elastic.NewQueryStringQuery(fmt.Sprintf("project_key:%s AND workflow_name:%s", p.Key, w)))
conditions = append(conditions,
osquery.Term("project_key", p.Key),
osquery.Term("workflow_name", w),
)
}
}

query := osquery.Query(osquery.Bool().Must(conditions...))
result, err := s.esClient.SearchDoc(ctx,
[]string{s.Cfg.ElasticSearch.IndexEvents},
fmt.Sprintf("%T", sdk.Event{}),
boolQuery,
[]elastic.Sorter{elastic.NewFieldSort("timestamp").Desc()},
s.Cfg.ElasticSearch.IndexEvents,
query,
[]string{"timestamp:desc"},
filters.CurrentItem, 15)
if err != nil {
if strings.Contains(err.Error(), indexNotFoundException) {
Expand Down Expand Up @@ -95,19 +101,21 @@ func (s *Service) getMetricsHandler() service.Handler {
return sdk.WrapError(err, "Unable to read request")
}

stringQuery := fmt.Sprintf("key:%s AND project_key:%s", request.Key, request.ProjectKey)
var conditions []osquery.Mappable
conditions = append(conditions, osquery.Term("key", request.Key))
conditions = append(conditions, osquery.Term("project_key", request.ProjectKey))
if request.ApplicationID != 0 {
stringQuery = fmt.Sprintf("%s AND application_id:%d", stringQuery, request.ApplicationID)
conditions = append(conditions, osquery.Term("application_id", strconv.FormatInt(request.ApplicationID, 10)))
}
if request.WorkflowID != 0 {
stringQuery = fmt.Sprintf("%s AND workflow_id:%d", stringQuery, request.WorkflowID)
conditions = append(conditions, osquery.Term("workflow_id", strconv.FormatInt(request.WorkflowID, 10)))
}

query := osquery.Query(osquery.Bool().Must(conditions...))
results, err := s.esClient.SearchDoc(ctx,
[]string{s.Cfg.ElasticSearch.IndexMetrics},
fmt.Sprintf("%T", sdk.Metric{}),
elastic.NewBoolQuery().Must(elastic.NewQueryStringQuery(stringQuery)),
[]elastic.Sorter{elastic.NewFieldSort("run").Desc()},
s.Cfg.ElasticSearch.IndexMetrics,
query,
[]string{"run:desc"},
-1, 10)
if err != nil {
if strings.Contains(err.Error(), indexNotFoundException) {
Expand Down Expand Up @@ -159,16 +167,16 @@ func (s *Service) getStatusHandler() service.Handler {

func (s *Service) loadMetric(ctx context.Context, ID string) (sdk.Metric, error) {
var m sdk.Metric
results, err := s.esClient.SearchDoc(ctx, []string{s.Cfg.ElasticSearch.IndexMetrics},
fmt.Sprintf("%T", sdk.Metric{}),
elastic.NewBoolQuery().Must(elastic.NewQueryStringQuery(fmt.Sprintf("_id:%s", ID))),
[]elastic.Sorter{
elastic.NewFieldSort("_score").Desc(),
elastic.NewFieldSort("run").Desc(),
}, -1, 10)

query := osquery.Query(osquery.IDs(ID))

results, err := s.esClient.SearchDoc(ctx, s.Cfg.ElasticSearch.IndexMetrics,
query,
[]string{"_score:desc", "run:desc"},
-1, 10)
if err != nil {
log.Warn(ctx, "elasticsearch> loadMetric> %v", err.Error())
if strings.Contains(err.Error(), indexNotFoundException) {
log.Warn(ctx, "elasticsearch> loadMetric> %v", err.Error())
return m, nil
}
return m, sdk.WrapError(err, "unable to get result")
Expand All @@ -178,6 +186,8 @@ func (s *Service) loadMetric(ctx context.Context, ID string) (sdk.Metric, error)
return m, nil
}

log.Info(ctx, "loadMetric : %v", string(results.Hits.Hits[0].Source))

if err := sdk.JSONUnmarshal(results.Hits.Hits[0].Source, &m); err != nil {
return m, err
}
Expand Down
Loading