Skip to content

Commit 1b81729

Browse files
authored
Merge branch 'master' into dependabot/go_modules/github.com/openshift-online/ocm-sdk-go-0.1.497
2 parents 17c8f1e + 1f171d6 commit 1b81729

File tree

10 files changed

+164
-236
lines changed

10 files changed

+164
-236
lines changed

.github/workflows/bdd.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2023-2026 Red Hat, Inc
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: BDD tests
16+
17+
on:
18+
push:
19+
branches: ["master", "main"]
20+
pull_request:
21+
22+
jobs:
23+
bdd:
24+
name: BDD tests
25+
uses: RedHatInsights/processing-tools/.github/workflows/bdd.yaml@master
26+
with:
27+
service: smart-proxy

.github/workflows/bdd.yml

Lines changed: 0 additions & 42 deletions
This file was deleted.

pr_check.sh

Lines changed: 0 additions & 77 deletions
This file was deleted.

server/api/v2/openapi.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,9 @@
488488
},
489489
"/cluster/{clusterId}/request/{requestId}/status": {
490490
"get": {
491-
"summary": "Check status of a given cluster's request",
491+
"summary": "Check the status of a given request_id, representing a single archive uploaded by the Insights Operator to Ingress. Doesn't distinguish between regular archives and those collected on-demand",
492492
"operationId": "getRequestStatusForCluster",
493-
"description": "The status of the request with given ID if found. The cluster ID is required so only requests for the given cluster are returned, if any. Response should have the following format: ```\n{\n\"cluster\": \"{clusterID}\",\n\"requestID\":\"{requestID}\",\n\"status\": \"{string}\"\n}\n```",
493+
"description": "This endpoint is to be used as a simple check whether a given cluster archive has been processed successfully. It's primarily used by the Insights Operator's on-demand data gathering feature to check whether an archive has been processed and stored successfully. The response should have the following format: ```\n{\n\"cluster\": \"{clusterID}\",\n\"requestID\":\"{requestID}\",\n\"status\": \"{string}\"\n}\n```",
494494
"parameters": [
495495
{
496496
"name": "clusterId",
@@ -512,7 +512,7 @@
512512
],
513513
"responses": {
514514
"200": {
515-
"description": "Stored status for the given cluster and request IDs",
515+
"description": "A successful response means that the given request_id (a single Insights Operator archive uploaded to Ingress) has been successfully processed, stored, and the Insights results are available for retrieval",
516516
"content": {
517517
"application/json": {
518518
"schema": {
@@ -538,13 +538,13 @@
538538
}
539539
},
540540
"400": {
541-
"description": "Invalid request or invalid cluster ID"
541+
"description": "Invalid request, invalid cluster_id param or invalid request_id param"
542542
},
543543
"403": {
544544
"$ref": "#/components/responses/unauthorized"
545545
},
546546
"404": {
547-
"description": "Request ID or cluster ID not found"
547+
"description": "Request ID not found for given org_id and cluster_id. Doesn't distinguish between different processing states. The 404 response simply indicates that we don't have any information about the given request_id"
548548
}
549549
}
550550
}

server/endpoints_v2.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ func (server *HTTPServer) addV2EndpointsToRouter(router *mux.Router) {
166166
}
167167

168168
// addV2RedisEndpointsToRouter method registers handlers for endpoints that depend on our Redis storage
169-
// to provide responses.
169+
// to provide responses. These endpoints are used by the insights-operator, which is a versioned product,
170+
// meaning these endpoints have to be 100% backwards compatible.
170171
func (server *HTTPServer) addV2RedisEndpointsToRouter(router *mux.Router, apiPrefix string) {
171172
router.HandleFunc(apiPrefix+ListAllRequestIDs, server.getRequestsForCluster).Methods(http.MethodGet)
172173
router.HandleFunc(apiPrefix+ListAllRequestIDs, server.getRequestsForClusterPostVariant).Methods(http.MethodPost)

server/handlers_v2.go

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,8 +1281,10 @@ func (server *HTTPServer) processClustersDetailResponse(
12811281
return responses.Send(http.StatusOK, writer, response)
12821282
}
12831283

1284-
// getRequestStatusForCluster method implements endpoint that should return a status
1285-
// for given request ID.
1284+
// getRequestStatusForCluster implements an endpoint returning the status of a
1285+
// given request ID.
1286+
// This endpoint was previously causing a performance issue affecting the insights-operator. We need to ensure
1287+
// that this endpoint will always be 100% backwards compatible.
12861288
func (server *HTTPServer) getRequestStatusForCluster(writer http.ResponseWriter, request *http.Request) {
12871289
orgID, err := server.GetCurrentOrgID(request)
12881290
if err != nil {
@@ -1305,42 +1307,28 @@ func (server *HTTPServer) getRequestStatusForCluster(writer http.ResponseWriter,
13051307

13061308
// make sure we don't access server.redis when it's nil
13071309
if !server.checkRedisClientReadiness(writer) {
1308-
// error has been handled already
1310+
// error handled by function
13091311
return
13101312
}
13111313

1312-
// get request ID list from Redis using SCAN command
1313-
requestIDsForCluster, err := server.redis.GetRequestIDsForClusterID(orgID, clusterID)
1314+
// perform EXISTS query to check whether an archive (request_id) was processed
1315+
err = server.redis.GetRequestStatus(orgID, clusterID, requestID)
13141316
if err != nil {
1315-
handleServerError(writer, err)
1316-
return
1317-
}
1318-
if len(requestIDsForCluster) == 0 {
1319-
err := responses.SendNotFound(writer, RequestsForClusterNotFound)
1320-
if err != nil {
1321-
log.Error().Err(err).Msg(responseDataError)
1322-
}
1323-
return
1324-
}
1325-
1326-
// try to find the required request ID in list of requests IDs from Redis
1327-
var found bool
1328-
for _, storedRequestID := range requestIDsForCluster {
1329-
if storedRequestID == requestID {
1330-
found = true
1331-
break
1332-
}
1333-
}
1334-
1335-
if !found {
1336-
err := responses.SendNotFound(writer, RequestIDNotFound)
1337-
if err != nil {
1338-
log.Error().Err(err).Msg(responseDataError)
1317+
switch err.(type) {
1318+
case *utypes.ItemNotFoundError:
1319+
// keep same message as in the original endpoint
1320+
err := responses.SendNotFound(writer, RequestIDNotFound)
1321+
if err != nil {
1322+
log.Error().Err(err).Msg(responseDataError)
1323+
}
1324+
return
1325+
default:
1326+
handleServerError(writer, err)
1327+
return
13391328
}
1340-
return
13411329
}
13421330

1343-
// prepare data structure
1331+
// prepare response
13441332
responseData := map[string]interface{}{}
13451333
responseData["cluster"] = string(clusterID)
13461334
responseData["requestID"] = requestID

0 commit comments

Comments
 (0)