Skip to content

Commit

Permalink
fix(elasticsearch): type ES (#5008)
Browse files Browse the repository at this point in the history
* fix(elasticsearch): type ES

close #4528

Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Feb 26, 2020
1 parent dc21e90 commit d21619b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ COPY dist/cds-worker-* /app/
COPY dist/sql.tar.gz /app/
COPY dist/ui.tar.gz /app/

RUN groupadd -r cds && useradd -r -g cds cds
RUN groupadd -r cds && useradd --create-home -r -g cds cds
RUN chmod +w /app/panic_dumps && \
chmod +x /app/cds-engine-linux-amd64 && \
tar xzf /app/sql.tar.gz -C /app/sql && \
Expand Down
11 changes: 9 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ services:
elasticsearch.URL=http://cds-elasticsearch:8088 \
elasticsearch.api.http.url=http://cds-api:8081 \
elasticsearch.name=cds-elasticsearch \
elasticsearch.elasticsearch.indexEvents=cds-indexEvents \
elasticsearch.elasticsearch.indexMetrics=cds-indexEvents \
elasticsearch.elasticsearch.indexEvents=cds-index-events \
elasticsearch.elasticsearch.indexMetrics=cds-index-events \
elasticsearch.elasticsearch.url=http://elasticsearch:9200 \
ui.url=http://${HOSTNAME}:8080 \
ui.api.http.url=http://cds-api:8081 \
Expand Down Expand Up @@ -248,6 +248,13 @@ services:
- "2023:2023"
- "2024:2024"

kibana:
image: docker.elastic.co/kibana/kibana-oss:6.7.2
ports:
- "127.0.0.1:5601:5601"
links:
- elasticsearch

volumes:
cds-artifacts-volume:
cds-repositories-volume:
Expand Down
10 changes: 5 additions & 5 deletions engine/elasticsearch/elasticsearch_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ func (s *Service) getEventsHandler() service.Handler {
}

boolQuery := elastic.NewBoolQuery()
boolQuery.Must(elastic.NewQueryStringQuery("type_event:sdk.EventRunWorkflow"))
for _, p := range filters.Filter.Projects {
for _, w := range p.WorkflowNames {
boolQuery.Should(elastic.NewQueryStringQuery(fmt.Sprintf("project_key:%s AND workflow_name:%s", p.Key, w)))
boolQuery.Must(elastic.NewQueryStringQuery(fmt.Sprintf("project_key:%s AND workflow_name:%s", p.Key, w)))
}

}
result, errR := esClient.Search().Index(s.Cfg.ElasticSearch.IndexEvents).Type("sdk.EventRunWorkflow").Query(boolQuery).Sort("timestamp", false).From(filters.CurrentItem).Size(15).Do(context.Background())
result, errR := esClient.Search().Index(s.Cfg.ElasticSearch.IndexEvents).Type(fmt.Sprintf("%T", sdk.Event{})).Query(boolQuery).Sort("timestamp", false).From(filters.CurrentItem).Size(15).Do(context.Background())
if errR != nil {
if strings.Contains(errR.Error(), indexNotFoundException) {
log.Warning(ctx, "elasticsearch> getEventsHandler> %v", errR.Error())
return service.WriteJSON(w, nil, http.StatusOK)
}
esReq := fmt.Sprintf(`esClient.Search().Index(%+v).Type("sdk.EventRunWorkflow").Query(%+v).Sort("timestamp", false).From(%+v).Size(15)`, s.Cfg.ElasticSearch.IndexEvents, boolQuery, filters.CurrentItem)
esReq := fmt.Sprintf(`esClient.Search().Index(%+v).Type("%T").Query(%+v).Sort("timestamp", false).From(%+v).Size(15)`, s.Cfg.ElasticSearch.IndexEvents, sdk.Event{}, boolQuery, filters.CurrentItem)
return sdk.WrapError(errR, "Cannot get result on index: %s : query -> %s", s.Cfg.ElasticSearch.IndexEvents, esReq)
}
return service.WriteJSON(w, result.Hits.Hits, http.StatusOK)
Expand All @@ -56,7 +56,7 @@ func (s *Service) postEventHandler() service.Handler {
return sdk.WrapError(err, "Unable to read body")
}

_, errI := esClient.Index().Index(s.Cfg.ElasticSearch.IndexEvents).Type(e.EventType).BodyJson(e).Do(context.Background())
_, errI := esClient.Index().Index(s.Cfg.ElasticSearch.IndexEvents).Type(fmt.Sprintf("%T", sdk.Event{})).BodyJson(e).Do(context.Background())
if errI != nil {
return sdk.WrapError(errI, "Unable to insert event")
}
Expand Down

0 comments on commit d21619b

Please sign in to comment.