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

Nodejs counters and lists #3726

Merged
merged 29 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e2d614d
Add getCounterCount
steven-supersolid Mar 9, 2024
276201d
Add types
steven-supersolid Mar 9, 2024
7f2510c
Implement incrementCounter
steven-supersolid Mar 10, 2024
ba75ad0
Implement decrementCounter
steven-supersolid Mar 10, 2024
f7f3308
Implement setCounterCount
steven-supersolid Mar 10, 2024
c98a9bc
Implement getCounterCapacity
steven-supersolid Mar 10, 2024
1a45bc1
Implement setCounterCapacity
steven-supersolid Mar 10, 2024
77e2f33
Implement list requests
steven-supersolid Mar 24, 2024
ab4e918
Fix int64 values
steven-supersolid Mar 24, 2024
2f35140
Example usage
steven-supersolid Mar 24, 2024
f3a4992
Remove boolean return types. Update packages
steven-supersolid May 12, 2024
b0a1666
Update example, fix SDK and tests
steven-supersolid May 12, 2024
c8979d8
update conformance test
steven-supersolid May 12, 2024
6496474
Merge remote-tracking branch 'upstream/main' into nodejs.CountsAndLists
steven-supersolid May 12, 2024
4104682
Update package-lock.json
steven-supersolid May 12, 2024
6a56575
Update gameserver-counts-and-lists.yaml
steven-supersolid May 12, 2024
999c31d
Split beta methods out of alpha
steven-supersolid May 14, 2024
2c5fc4b
Merge branch 'main' into nodejs.CountsAndLists
steven-supersolid May 16, 2024
a786e2a
Fix typo and update example
steven-supersolid May 16, 2024
795d0e7
Merge branch 'main' into nodejs.CountsAndLists
steven-supersolid May 17, 2024
e8075db
Update testSDKClient.js
steven-supersolid May 21, 2024
1f9ad51
Output arguments test
steven-supersolid May 22, 2024
68eeea4
Update make file for Node.js conformance tests
steven-supersolid May 23, 2024
e79c64a
Enable standard counts and lists tests
steven-supersolid May 23, 2024
e7d5c6c
alpha --> beta
steven-supersolid May 23, 2024
935b47a
Update nodejs-simple
steven-supersolid May 29, 2024
ca61c4b
Update build/includes/sdk.mk
steven-supersolid May 31, 2024
441aa48
Merge branch 'main' into nodejs.CountsAndLists
steven-supersolid May 31, 2024
495abda
Merge branch 'main' into nodejs.CountsAndLists
steven-supersolid Jun 2, 2024
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
3 changes: 2 additions & 1 deletion build/includes/sdk.mk
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ run-sdk-conformance-test-cpp:
$(MAKE) run-sdk-conformance-test SDK_FOLDER=cpp GRPC_PORT=9003 HTTP_PORT=9103

run-sdk-conformance-test-node:
$(MAKE) run-sdk-conformance-test SDK_FOLDER=node GRPC_PORT=9002 HTTP_PORT=9102
# run with on-by-default (Beta) feature flags enabled
$(MAKE) run-sdk-conformance-test SDK_FOLDER=node GRPC_PORT=9002 HTTP_PORT=9102 TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(COUNTS_AND_LISTS_TESTS)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By itself, this fails with error:

~/agones/build$ make run-sdk-conformance-test-node
...
> node ./testSDKClient.js

node:internal/modules/cjs/loader:1148
  throw err;
  ^

Error: Cannot find module '@grpc/grpc-js'
Require stack:
- /go/src/agones.dev/agones/sdks/nodejs/src/agonesSDK.js
- /go/src/agones.dev/agones/sdks/nodejs/src/index.js
- /go/src/agones.dev/agones/test/sdk/nodejs/testSDKClient.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
    at Module._load (node:internal/modules/cjs/loader:986:27)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/go/src/agones.dev/agones/sdks/nodejs/src/agonesSDK.js:15:14)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/go/src/agones.dev/agones/sdks/nodejs/src/agonesSDK.js',
    '/go/src/agones.dev/agones/sdks/nodejs/src/index.js',
    '/go/src/agones.dev/agones/test/sdk/nodejs/testSDKClient.js'
  ]
}

Once I run ~/agones/build$ SDK_FOLDER=node make test-sdk it installs the dependencies successfully, and then the command ~/agones/build$ make run-sdk-conformance-test-node runs successfully. If there's not a quick way to check that the build script was run as part of the run-sdk-conformance-test-node we should probably add a comment noting that SDK_FOLDER=node make test-sdk needs to be run first.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would need to execute npm install in the sdk folder, e.g. in build-sdk-test.sh the minimum required is

cd /go/src/agones.dev/agones/test/sdk/nodejs
npm install --quiet

Could we add something like that here? I don't know enough about these makefiles

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not worth modifying the make command, since the test gets build properly during CI / CD, so this only applies to local testing. I added in a suggested comment change above.


run-sdk-conformance-test-go:
# run with on-by-default (Beta) feature flags enabled
Expand Down
45 changes: 45 additions & 0 deletions examples/nodejs-simple/gameserver-counts-and-lists.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
# Copyright 2020 Google LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: agones.dev/v1
kind: GameServer
metadata:
generateName: simple-game-server-
spec:
ports:
- name: default
portPolicy: Dynamic
containerPort: 7654
counters:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this to test with the local server but neither the counter or list can be found, so perhaps the structure is incorrect?
I started with

sdk-server.windows.amd64.exe --local --feature-gates CountsAndLists=true -f gameserver-counts-and-lists.yaml 

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you want the example to have the same counter and list as the local SDK Server? The sample local SDK server counters is "rooms" and lists is "players"

if runtime.FeatureEnabled(runtime.FeatureCountsAndLists) {
gs.Status.Counters = map[string]*sdk.GameServer_Status_CounterStatus{
"rooms": {Count: 1, Capacity: 10},
}
gs.Status.Lists = map[string]*sdk.GameServer_Status_ListStatus{
"players": {Values: []string{"test0", "test1", "test2"}, Capacity: 100},
}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, that's what I needed, so can perhaps remove this file and update the example

games:
count: 1
capacity: 10
lists:
rooms:
capacity: 5
values:
- room1
- room2
template:
spec:
containers:
- name: simple-game-server
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27
resources:
requests:
memory: 64Mi
cpu: 20m
limits:
memory: 64Mi
cpu: 20m
19 changes: 10 additions & 9 deletions examples/nodejs-simple/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 100 additions & 21 deletions examples/nodejs-simple/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {setTimeout} = require('timers/promises');
const DEFAULT_TIMEOUT = 60;
const MAX_TIMEOUT = 2147483;

const connect = async (timeout, enableAlpha) => {
const connect = async (timeout, enableAlpha, enableBeta) => {
let agonesSDK = new AgonesSDK();

let lifetimeInterval;
Expand Down Expand Up @@ -56,32 +56,37 @@ const connect = async (timeout, enableAlpha) => {
process.exit(0);
});

await setTimeout(10000);
await setTimeout(5000);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shortening the delay as there as so many calls now

console.log('Setting a label');
await agonesSDK.setLabel('test-label', 'test-value');

await setTimeout(10000);
await setTimeout(5000);
console.log('Setting an annotation');
await agonesSDK.setAnnotation('test-annotation', 'test value');

await setTimeout(10000);
await setTimeout(5000);
console.log('Marking server as ready...');
await agonesSDK.ready();

await setTimeout(10000);
await setTimeout(5000);
console.log('Allocating');
await agonesSDK.allocate();

await setTimeout(10000);
await setTimeout(5000);
console.log('Reserving for 10 seconds');
await agonesSDK.reserve(10);
await setTimeout(20000);
await setTimeout(15000);

if (enableAlpha) {
console.log('Running alpha suite');
await runAlphaSuite(agonesSDK);
}

if (enableBeta) {
console.log('Running beta suite');
await runBetaSuite(agonesSDK);
}

if (timeout === 0) {
do {
await setTimeout(MAX_TIMEOUT);
Expand All @@ -93,12 +98,12 @@ const connect = async (timeout, enableAlpha) => {
console.log('Shutting down...');
agonesSDK.shutdown();

await setTimeout(10000);
await setTimeout(5000);
console.log('Closing connection to SDK server');
clearInterval(healthInterval);
agonesSDK.close();

await setTimeout(10000);
await setTimeout(5000);
console.log('Exiting');
clearInterval(lifetimeInterval);

Expand All @@ -113,58 +118,126 @@ const connect = async (timeout, enableAlpha) => {
};

const runAlphaSuite = async (agonesSDK) => {
await setTimeout(10000);
await setTimeout(5000);
console.log('Setting capacity');
await agonesSDK.alpha.setPlayerCapacity(64);

await setTimeout(10000);
await setTimeout(5000);
console.log('Getting capacity');
let result = await agonesSDK.alpha.getPlayerCapacity();
console.log(`result: ${result}`);

await setTimeout(10000);
await setTimeout(5000);
console.log('Connecting a player');
result = await agonesSDK.alpha.playerConnect('firstPlayerID');
console.log(`result: ${result}`);

await setTimeout(10000);
await setTimeout(5000);
console.log('Connecting a duplicate player');
result = await agonesSDK.alpha.playerConnect('firstPlayerID');
console.log(`result: ${result}`);

await setTimeout(10000);
await setTimeout(5000);
console.log('Connecting another player');
await agonesSDK.alpha.playerConnect('secondPlayerID');

await setTimeout(10000);
await setTimeout(5000);
console.log('Getting player count');
result = await agonesSDK.alpha.getPlayerCount();
console.log(`result: ${result}`);

await setTimeout(10000);
await setTimeout(5000);
console.log('Finding if firstPlayerID connected');
result = await agonesSDK.alpha.isPlayerConnected('firstPlayerID');
console.log(`result: ${result}`);

await setTimeout(10000);
await setTimeout(5000);
console.log('Getting connected players');
result = await agonesSDK.alpha.getConnectedPlayers();
console.log(`result: ${result}`);

await setTimeout(10000);
await setTimeout(5000);
console.log('Disconnecting a player');
result = await agonesSDK.alpha.playerDisconnect('firstPlayerID');
console.log(`result: ${result}`);

await setTimeout(10000);
await setTimeout(5000);
console.log('Disconnecting the same player');
result = await agonesSDK.alpha.playerDisconnect('firstPlayerID');
console.log(`result: ${result}`);

await setTimeout(5000);
console.log('Setting counter capacity');
result = await agonesSDK.alpha.setCounterCapacity('testCounter', 10);
console.log(`result: ${result}`);
};

const runBetaSuite = async (agonesSDK) => {
let result;

await setTimeout(5000);
console.log('Getting counter count');
result = await agonesSDK.beta.getCounterCount('games');
console.log(`result: ${result}`);

await setTimeout(5000);
console.log('Incrementing counter');
await agonesSDK.beta.incrementCounter('games', 1);

await setTimeout(5000);
console.log('Decrementing counter');
await agonesSDK.beta.decrementCounter('games', 1);

await setTimeout(5000);
console.log('Setting counter count');
await agonesSDK.beta.setCounterCount('games', 2);

await setTimeout(5000);
console.log('Getting counter capacity');
result = await agonesSDK.beta.getCounterCapacity('games');
console.log(`result: ${result}`);

await setTimeout(5000);
console.log('Setting counter capacity');
await agonesSDK.beta.setCounterCapacity('games', 200);

await setTimeout(5000);
console.log('Getting list capacity');
result = await agonesSDK.beta.getListCapacity('rooms');
console.log(`result: ${result}`);

await setTimeout(5000);
console.log('Setting list capacity');
await agonesSDK.beta.setListCapacity('rooms', 10);

await setTimeout(5000);
console.log('Getting list contains');
result = await agonesSDK.beta.listContains('rooms', 'room1');
console.log(`result: ${result}`);

await setTimeout(5000);
console.log('Getting list length');
result = await agonesSDK.beta.getListLength('rooms');
console.log(`result: ${result}`);

await setTimeout(5000);
console.log('Getting list values');
result = await agonesSDK.beta.getListValues('rooms');
console.log(`result: ${result}`);

await setTimeout(5000);
console.log('Appending list value');
await agonesSDK.beta.appendListValue('rooms', 'room3');

await setTimeout(5000);
console.log('Deleting list value');
await agonesSDK.beta.deleteListValue('rooms', 'room3');
};

let args = process.argv.slice(2);
let timeout = DEFAULT_TIMEOUT;
let enableAlpha = false;
let enableBeta = false;

for (let arg of args) {
let [argName, argValue] = arg.split('=');
Expand All @@ -173,7 +246,8 @@ for (let arg of args) {

Options:
--timeout=...\t\tshutdown timeout in seconds. Use 0 to never shut down
--alpha\t\t\tenable alpha features`);
--alpha\t\t\tenable alpha features
--beta\t\t\tenable beta features`);
return;
}
if (argName === '--timeout') {
Expand All @@ -194,6 +268,11 @@ Options:
console.log('Enabling alpha features!');
enableAlpha = true;
}

if (argName === '--beta') {
console.log('Enabling beta features!');
enableBeta = true;
}
}

connect(timeout, enableAlpha);
connect(timeout, enableAlpha, enableBeta);
Loading
Loading