Skip to content

Commit 529ff35

Browse files
debug port not readyz
1 parent fb0d7a9 commit 529ff35

File tree

9 files changed

+145
-101
lines changed

9 files changed

+145
-101
lines changed

tests/acceptance/TestHelpers/OcisConfigHelper.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,17 @@ public static function startOcis(): ResponseInterface {
123123

124124
/**
125125
* this method stops the running oCIS instance,
126-
* restarts it while excluding specific services,
126+
* restarts oCIS without specific services,
127127
* and then starts the excluded services separately.
128128
*
129129
* @param string $service
130+
* @param array $envs
130131
*
131132
* @return ResponseInterface
132133
* @throws GuzzleException
133134
*/
134-
public static function startService(string $service): ResponseInterface {
135+
public static function startService(string $service, array $envs = []): ResponseInterface {
135136
$url = self::getWrapperUrl() . "/services/" . $service;
136-
return self::sendRequest($url, "POST");
137+
return self::sendRequest($url, "POST", \json_encode($envs));
137138
}
138139
}

tests/acceptance/bootstrap/OcisConfigContext.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,24 @@ public function theConfigHasBeenSetToValue(TableNode $table): void {
192192
}
193193

194194
/**
195-
* @Given the administrator has started service :service separately
195+
* @Given the administrator has started service :service separately with the following configs:
196196
*
197197
* @param string $service
198+
* @param TableNode $table
198199
*
199200
* @return void
200201
* @throws GuzzleException
201202
*/
202-
public function theAdministratorHasStartedServiceSeparately(string $service): void {
203-
$response = OcisConfigHelper::startService($service);
203+
public function theAdministratorHasStartedServiceSeparatelyWithTheFollowingConfig(
204+
string $service,
205+
TableNode $table
206+
): void {
207+
$envs = [];
208+
foreach ($table->getHash() as $row) {
209+
$envs[$row['config']] = $row['value'];
210+
}
204211

212+
$response = OcisConfigHelper::startService($service, $envs);
205213
Assert::assertEquals(
206214
200,
207215
$response->getStatusCode(),

tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md

+1
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ The expected failures in this file are from features in the owncloud/ocis repo.
323323
#### [Readiness check for some services returns 500 status code](https://github.com/owncloud/ocis/issues/10661)
324324
- [apiServiceAvailability/serviceAvailabilityCheck.feature:111](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiServiceAvailability/serviceAvailabilityCheck.feature#L111)
325325
- [apiServiceAvailability/serviceAvailabilityCheck.feature:120](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiServiceAvailability/serviceAvailabilityCheck.feature#L120)
326+
- [apiServiceAvailability/serviceAvailabilityCheck.feature:131](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiServiceAvailability/serviceAvailabilityCheck.feature#L131)
326327

327328
Note: always have an empty line at the end of this file.
328329
The bash script that processes this file requires that the last line has a newline on the end.

tests/acceptance/features/apiServiceAvailability/serviceAvailabilityCheck.feature

+23-16
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ Feature: service health check
4343
@env-config
4444
Scenario: check extra services health
4545
Given the following configs have been set:
46-
| config | value |
47-
| OCIS_ADD_RUN_SERVICES | auth-app,auth-bearer,policies,invitations |
48-
| AUTH_APP_DEBUG_ADDR | 0.0.0.0:9245 |
49-
| POLICIES_DEBUG_ADDR | 0.0.0.0:9129 |
50-
| INVITATIONS_DEBUG_ADDR | 0.0.0.0:9269 |
46+
| config | value |
47+
| OCIS_ADD_RUN_SERVICES | auth-app,policies,invitations |
48+
| AUTH_APP_DEBUG_ADDR | 0.0.0.0:9245 |
49+
| POLICIES_DEBUG_ADDR | 0.0.0.0:9129 |
50+
| INVITATIONS_DEBUG_ADDR | 0.0.0.0:9269 |
5151
When a user requests these URLs with "GET" and no authentication
5252
| endpoint | service |
5353
| http://%base_url_hostname%:9245/healthz | auth-app |
@@ -116,6 +116,17 @@ Feature: service health check
116116
| http://%base_url_hostname%:9205/readyz | proxy |
117117
Then the HTTP status code of responses on all endpoints should be "200"
118118

119+
@env-config @issue-10661
120+
Scenario: check auth-bearer service health
121+
Given the following configs have been set:
122+
| config | value |
123+
| OCIS_ADD_RUN_SERVICES | auth-bearer |
124+
| AUTH_BEARER_DEBUG_ADDR | 0.0.0.0:9149 |
125+
When a user requests these URLs with "GET" and no authentication
126+
| endpoint | service |
127+
| http://%base_url_hostname%:9149/healthz | auth-bearer |
128+
Then the HTTP status code should be "200"
129+
119130
@env-config @issue-10661
120131
Scenario: check auth-bearer service readiness
121132
Given the following configs have been set:
@@ -125,20 +136,16 @@ Feature: service health check
125136
When a user requests these URLs with "GET" and no authentication
126137
| endpoint | service |
127138
| http://%base_url_hostname%:9149/readyz | auth-bearer |
128-
Then the HTTP status code of responses on all endpoints should be "200"
139+
Then the HTTP status code should be "200"
129140

130141
@env-config
131-
Scenario: check services health while running separately
132-
Given the administrator has started service "audit" separately
142+
Scenario: check services health and readiness while running separately
143+
Given the administrator has started service "audit" separately with the following configs:
144+
| config | value |
145+
| OCIS_LOG_LEVEL | info |
146+
| AUDIT_DEBUG_ADDR | 0.0.0.0:9229 |
133147
When a user requests these URLs with "GET" and no authentication
134148
| endpoint | service |
135149
| http://%base_url_hostname%:9229/healthz | audit |
136-
Then the HTTP status code of responses on all endpoints should be "200"
137-
138-
@env-config
139-
Scenario: check services readiness while running separately
140-
Given the administrator has started service "audit" separately
141-
When a user requests these URLs with "GET" and no authentication
142-
| endpoint | service |
143-
| http://%base_url_hostname%:9229/readyz | audit |
150+
| http://%base_url_hostname%:9229/readyz | audit |
144151
Then the HTTP status code of responses on all endpoints should be "200"

tests/acceptance/features/cliCommands/backupConsistency.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ Feature: backup consistency
5353
And the administrator has started the server
5454
When user "Alice" gets the number of versions of file "/textfile0.txt"
5555
Then the HTTP status code should be "207"
56-
And the number of versions should be "2"
56+
And the number of versions should be "2"

tests/ociswrapper/README.md

+17-13
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,28 @@ Also, see `./bin/ociswrapper help` for more information.
125125
- `200 OK` - oCIS server is stopped
126126
- `500 Internal Server Error` - Unable to stop oCIS server
127127

128-
6. `POST /services/{service-name}`
128+
6. `POST /services/{service-name}`
129129

130-
Restart oCIS with service excluded and start excluded oCIS service individually, not covered by the oCIS supervisor.
130+
Restart oCIS with service excluded and start excluded oCIS service individually, not covered by the oCIS supervisor.
131131

132-
Body of the request should be a JSON object with the following structure:
132+
Body of the request should be a JSON object with the following structure:
133133

134-
```json
135-
{
136-
"ENV_KEY1": "value1",
137-
"ENV_KEY2": "value2"
138-
}
139-
```
134+
```json
135+
{
136+
"ENV_KEY1": "value1",
137+
"ENV_KEY2": "value2"
138+
}
139+
```
140140

141-
Returns:
141+
> **⚠️ WARNING:**
142+
> You need to set the address of the debug server to expose the port in CI
143+
> `{SERVICE-NAME}_DEBUG_ADDR`
144+
145+
Returns:
142146

143147
- `200 OK` - oCIS server is stopped
144-
- `500 Internal Server Error` - Unable to stop oCIS server
148+
- `400 Bad Request` - request body is not a valid JSON object
149+
- `500 Internal Server Error` - Unable to start oCIS service
145150

146151
7. `DELETE /services/{service-name}`
147152

@@ -150,5 +155,4 @@ Also, see `./bin/ociswrapper help` for more information.
150155
Returns:
151156

152157
- `200 OK` - command is successfully executed
153-
- `400 Bad Request` - request body is not a valid JSON object
154-
- `500 Internal Server Error`
158+
- `500 Internal Server Error` - Unable to start oCIS service

tests/ociswrapper/ocis/config/config.go

+51
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,61 @@ var config = map[string]string{
88
"adminPassword": "",
99
}
1010

11+
var services = map[string]int{
12+
"ocis": 9250,
13+
"activitylog": 9197,
14+
"app-provider": 9165,
15+
"app-registry": 9243,
16+
"audit": 9149,
17+
"auth-app": 9245,
18+
"auth-bearer": 9149,
19+
"auth-basic": 9147,
20+
"auth-machine": 9167,
21+
"auth-service": 9198,
22+
"clientlog": 9260,
23+
"eventhistory": 9270,
24+
"frontend": 9141,
25+
"gateway": 9143,
26+
"graph": 9124,
27+
"groups": 9161,
28+
"idm": 9239,
29+
"idp": 9134,
30+
"invitations": 9269,
31+
"nats": 9234,
32+
"ocdav": 9163,
33+
"ocm": 9281,
34+
"ocs": 9114,
35+
"policies": 9129,
36+
"postprocessing": 9255,
37+
"proxy": 9205,
38+
"search": 9224,
39+
"settings": 9194,
40+
"sharing": 9151,
41+
"sse": 9139,
42+
"storage-publiclink": 9179,
43+
"storage-shares": 9156,
44+
"storage-system": 9217,
45+
"storage-users": 9159,
46+
"thumbnails": 9189,
47+
"userlog": 9214,
48+
"users": 9145,
49+
"web": 9104,
50+
"webdav": 9119,
51+
"webfinger": 9279,
52+
}
53+
1154
func Set(key string, value string) {
1255
config[key] = value
1356
}
1457

1558
func Get(key string) string {
1659
return config[key]
1760
}
61+
62+
func SetService(key string, value int) {
63+
services[key] = value
64+
}
65+
66+
func GetService(key string) int {
67+
return services[key]
68+
}

tests/ociswrapper/ocis/ocis.go

+27-64
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func waitUntilCompleteShutdown() (bool, string) {
145145
timeout := 30 * time.Second
146146
startTime := time.Now()
147147

148-
c := exec.Command("sh", "-c", "ps ax | grep '[o]cis server' | grep -v grep | awk '{print $1}'")
148+
c := exec.Command("sh", "-c", "ps ax | grep 'ocis server' | grep -v grep | awk '{print $1}'")
149149
output, err := c.CombinedOutput()
150150
if err != nil {
151151
log.Println(err.Error())
@@ -223,6 +223,7 @@ func StartService(service string, envMap []string) {
223223
} else {
224224
cmd.Env = append(os.Environ(), envMap...)
225225
}
226+
log.Println(fmt.Sprintf("%s", cmd.Env))
226227

227228
logs, err := cmd.StderrPipe()
228229
if err != nil {
@@ -251,7 +252,6 @@ func StartService(service string, envMap []string) {
251252

252253
for listService, pid := range runningServices {
253254
log.Println(fmt.Sprintf("%s service started with process id %v", listService, pid))
254-
WaitUntilPortListens(listService)
255255
}
256256

257257
// Read the logs when the 'ocis server' command is running
@@ -307,65 +307,25 @@ func StartService(service string, envMap []string) {
307307

308308
// Stop oCIS service or a specific service by its unique identifier
309309
func StopService(service string) (bool, string) {
310-
stopWg := new(sync.WaitGroup)
311-
stopWg.Add(1)
312-
313-
resultChan := make(chan struct {
314-
success bool
315-
message string
316-
}, 1)
317-
318-
go func() {
319-
defer stopWg.Done()
320-
321-
pid, exists := runningServices[service]
322-
if !exists {
323-
resultChan <- struct {
324-
success bool
325-
message string
326-
}{false, fmt.Sprintf("Service %s is not running", service)}
327-
return
328-
}
329-
330-
process, err := os.FindProcess(pid)
331-
if err != nil {
332-
resultChan <- struct {
333-
success bool
334-
message string
335-
}{false, fmt.Sprintf("Failed to find service %s process running with ID %d", service, pid)}
336-
return
337-
}
338-
339-
pKillError := process.Signal(syscall.SIGINT)
340-
if pKillError != nil {
341-
resultChan <- struct {
342-
success bool
343-
message string
344-
}{false, fmt.Sprintf("Failed to stop service with process id %d", pid)}
345-
return
346-
}
347-
348-
delete(runningServices, service)
349-
log.Println(fmt.Sprintf("oCIS service %s has been stopped successfully", service))
310+
pid, exists := runningServices[service]
311+
if !exists {
312+
return false, fmt.Sprintf("Service %s is not running", service)
313+
}
350314

351-
resultChan <- struct {
352-
success bool
353-
message string
354-
}{true, fmt.Sprintf("Service %s stopped successfully", service)}
355-
}()
315+
process, err := os.FindProcess(pid)
316+
if err != nil {
317+
return false, fmt.Sprintf("Failed to find service %s process running with ID %d", service, pid)
318+
}
356319

357-
// Wait for the goroutine to finish and retrieve the result.
358-
stopWg.Wait()
359-
result := <-resultChan
360-
close(resultChan)
320+
pKillError := process.Signal(syscall.SIGINT)
321+
if pKillError != nil {
322+
return false, fmt.Sprintf("Failed to stop service with process id %d", pid)
323+
}
361324

362-
return result.success, result.message
363-
}
325+
delete(runningServices, service)
326+
log.Println(fmt.Sprintf("oCIS service %s has been stopped successfully", service))
364327

365-
var servicePortMap = map[string]int{
366-
"ocis": 9250,
367-
"audit": 9229,
368-
"activitylog": 9197,
328+
return true, fmt.Sprintf("Service %s stopped successfully", service)
369329
}
370330

371331
// WaitUntilPortListens waits until the port for a given service is listening
@@ -374,11 +334,7 @@ func WaitUntilPortListens(service string) bool {
374334
ticker := time.NewTicker(2 * time.Second)
375335
defer ticker.Stop()
376336

377-
port, exists := servicePortMap[service]
378-
if !exists {
379-
log.Println(fmt.Sprintf("%s service port not mapped...", service))
380-
return false
381-
}
337+
port := config.GetService(service)
382338

383339
for {
384340
select {
@@ -387,15 +343,22 @@ func WaitUntilPortListens(service string) bool {
387343
log.Println(fmt.Errorf("timeout: %s service did not become available within 30 seconds", service).Error())
388344
return false
389345
case <-ticker.C:
346+
// Retry if the service is not in `runningServices`
347+
if _, exists := runningServices[service]; !exists {
348+
log.Println(fmt.Sprintf("Service %s not found in running services. Retrying...\n", service))
349+
continue
350+
}
351+
352+
// Check if the port is listening
390353
address := fmt.Sprintf(":%d", port)
391-
log.Println(fmt.Sprintf("Address %s\n", address))
392354
// Try to connect to the port
393355
conn, err := net.DialTimeout("tcp", address, 1*time.Second)
394356
if err == nil {
395357
_ = conn.Close()
396-
log.Println(fmt.Sprintf("%s service is ready", service))
358+
log.Println(fmt.Sprintf("%s service is ready to listen port %d", service, port))
397359
return true
398360
}
361+
log.Println(fmt.Sprintf("%v port is not ready %v\n", conn, err))
399362
}
400363
}
401364
}

0 commit comments

Comments
 (0)