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: Set unique default server port #805

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions charts/block-node-server/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
1. **Get the application URL** by running the following commands:

```bash
kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{.Release.Name}}-{{.Chart.Name}} 8080:{{ .Values.service.port }}
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{.Release.Name}}-{{.Chart.Name}} 40840:{{ .Values.service.port }}
echo "Visit http://127.0.0.1:40840 to use your application"
Comment on lines +4 to +5
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{.Release.Name}}-{{.Chart.Name}} 40840:{{ .Values.service.port }}
echo "Visit http://127.0.0.1:40840 to use your application"
kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{.Release.Name}}-{{.Chart.Name}} {{ .Values.service.port }}:{{ .Values.service.port }}
echo "Visit http://127.0.0.1:{{ .Values.service.port }} to use your application"

```

{{- if .Values.kubepromstack.enabled }}
Expand Down
2 changes: 1 addition & 1 deletion charts/block-node-server/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ securityContext: {}

service:
type: ClusterIP
port: 8080
port: 40840

ingress:
enabled: false
Expand Down
6 changes: 3 additions & 3 deletions server/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ ENV PATH=${JAVA_HOME}/bin:${PATH}
COPY --from=java-builder ${JAVA_HOME}/ ${JAVA_HOME}/

# Expose the port that the application will run on
EXPOSE 8080/tcp
EXPOSE 40840/tcp

USER hedera
WORKDIR /app

# HEALTHCHECK for liveness and readiness
HEALTHCHECK --interval=30s --timeout=10s --start-period=3s --retries=3 \
CMD curl -f http://localhost:8080/healthz/livez || exit 1 && \
curl -f http://localhost:8080/healthz/readyz || exit 1
CMD curl -f http://localhost:40840/healthz/livez || exit 1 && \
curl -f http://localhost:40840/healthz/readyz || exit 1

# RUN the bin script for starting the server
ENTRYPOINT ["/bin/bash", "-c", "/app/server-${VERSION}/bin/server"]
2 changes: 1 addition & 1 deletion server/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
env_file:
- .env
ports:
- "8080:8080"
- "40840:40840"
- "5005:5005"
- "9999:9999"
- "8849:8849"
Expand Down
2 changes: 1 addition & 1 deletion server/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defaults and can be left unchanged. It is recommended to browse the properties b
| SERVICE_DELAY_MILLIS | Service shutdown delay in milliseconds | 500 |
| MEDIATOR_RING_BUFFER_SIZE | Size of the ring buffer used by the mediator (must be a power of 2) | 67108864 |
| NOTIFIER_RING_BUFFER_SIZE | Size of the ring buffer used by the notifier (must be a power of 2) | 2048 |
| SERVER_PORT | The port the server will listen on | 8080 |
| SERVER_PORT | The port the server will listen on | 40840 |
| SERVER_MAX_MESSAGE_SIZE_BYTES | The maximum size of a message frame in bytes | 1048576 |
| VERIFICATION_ENABLED | Enables or disables the block verification process | true |
| VERIFICATION_SESSION_TYPE | The type of BlockVerificationSession to use, either `ASYNC` or `SYNC` | ASYNC |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public record ServerConfig(
static final int minSocketReceiveBufferSizeBytes = 32768;

// Constants for port property
static final String defaultPort = "8080";
static final String defaultPort = "40840";
static final int minPort = 1024;
static final int maxPort = 65_535;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
@ExtendWith(MockitoExtension.class)
class BlockNodeAppTest {

private static final int DEFAULT_PORT = 40840;

@Mock
private ServiceStatus serviceStatus;

Expand Down Expand Up @@ -84,7 +86,7 @@ void setup() throws IOException {
ConsumerConfig consumerConfig = config.getConfigData(ConsumerConfig.class);
ProducerConfig producerConfig = config.getConfigData(ProducerConfig.class);

serverConfig = new ServerConfig(4_194_304, 32_768, 32_768, 8080);
serverConfig = new ServerConfig(4_194_304, 32_768, 32_768, DEFAULT_PORT);

blockNodeApp = new BlockNodeApp(
serviceStatus,
Expand All @@ -104,7 +106,7 @@ void setup() throws IOException {
serverConfig,
configurationLogging);

when(webServerBuilder.port(8080)).thenReturn(webServerBuilder);
when(webServerBuilder.port(DEFAULT_PORT)).thenReturn(webServerBuilder);
when(webServerBuilder.addProtocol(any(PbjConfig.class))).thenReturn(webServerBuilder);
when(webServerBuilder.addRouting(any(PbjRouting.Builder.class))).thenReturn(webServerBuilder);
when(webServerBuilder.addRouting(any(HttpRouting.Builder.class))).thenReturn(webServerBuilder);
Expand All @@ -122,7 +124,7 @@ void testStartServer() throws IOException {
verify(serviceStatus).setWebServer(webServer);
verify(webServer).start();
verify(healthService).getHealthRootPath();
verify(webServerBuilder).port(8080);
verify(webServerBuilder).port(DEFAULT_PORT);
verify(webServerBuilder).addRouting(any(PbjRouting.Builder.class));
verify(webServerBuilder).addRouting(any(HttpRouting.Builder.class));
verify(webServerBuilder).addProtocol(any(PbjConfig.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class ServerConfigTest {

private static final String RANGE_ERROR_TEMPLATE = "%s value %d is out of range [%d, %d]";
private static final int DEFAULT_PORT = 40840;

@BeforeEach
void setUp() {}
Expand All @@ -24,32 +25,32 @@ void tearDown() {}

@Test
void testValidValues() {
ServerConfig serverConfig = new ServerConfig(4_194_304, 32_768, 32_768, 8080);
ServerConfig serverConfig = new ServerConfig(4_194_304, 32_768, 32_768, DEFAULT_PORT);
assertEquals(4_194_304, serverConfig.maxMessageSizeBytes());
assertEquals(8080, serverConfig.port());
assertEquals(DEFAULT_PORT, serverConfig.port());
}

@ParameterizedTest
@MethodSource("outOfRangeMaxMessageSizes")
void testMessageSizesOutOfBounds(final int messageSize, final String message) {
assertThatIllegalArgumentException()
.isThrownBy(() -> new ServerConfig(messageSize, 32_768, 32_768, 8080))
.isThrownBy(() -> new ServerConfig(messageSize, 32_768, 32_768, DEFAULT_PORT))
.withMessage(message);
}

@ParameterizedTest
@MethodSource("outOfRangeSendBufferSizes")
void testSocketSendBufferSize(int sendBufferSize, String message) {
assertThatIllegalArgumentException()
.isThrownBy(() -> new ServerConfig(4_194_304, sendBufferSize, 32_768, 8080))
.isThrownBy(() -> new ServerConfig(4_194_304, sendBufferSize, 32_768, DEFAULT_PORT))
.withMessage(message);
}

@ParameterizedTest
@MethodSource("outOfRangeReceiveBufferSizes")
void testSocketReceiveBufferSize(int receiveBufferSize, String message) {
assertThatIllegalArgumentException()
.isThrownBy(() -> new ServerConfig(4_194_304, 32_768, receiveBufferSize, 8080))
.isThrownBy(() -> new ServerConfig(4_194_304, 32_768, receiveBufferSize, DEFAULT_PORT))
.withMessage(message);
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/test/network-latency-simulator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM ubuntu:latest

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV GRPC_SERVER="host.docker.internal:8080"
ENV GRPC_SERVER="host.docker.internal:40840"
ENV GRPC_METHOD="BlockStreamGrpc/StreamSource"
ENV PATH_TO_PROTO="/usr/local/protos/blockstream.proto"
ENV PROTO_IMPORT_PATH="/usr/local/protos"
Expand Down
7 changes: 6 additions & 1 deletion server/src/test/network-latency-simulator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This test aims to make sure that the system is resilient to network issues and t

1. Move to the `network-latency-simulator` directory.
2. Prepare the Test Context, Build the Docker Image with the network latency simulator.

```bash
cd server/src/test/network-latency-simulator

Expand All @@ -21,11 +22,14 @@ docker build -t network-latency-simulator .
3. Start the BlockNode Server. (Follow instructions on main README.md)
- Due to the Latency, the consumers might be disconnected from the BlockNode, since the current timeout is 1500 ms, you should increase the timeout to 100000ms to be able to correctly test the network issues. (see main README.md of the server for more details on how to change the timeout)
4. Start the producer and a single consumer (this consumer will be the control one without any network issues).

```bash
/server/src/test/resources/producer.sh 1 1000 # this will produce 1000 blocks
/server/src/test/resources/consumer.sh 1 1000 # this will consume 1000 blocks
```

5. Start the consumer inside the network latency simulator container, you can start as many as you want.

```bash
docker run -it --cap-add=NET_ADMIN network-latency-simulator
```
Expand All @@ -48,12 +52,13 @@ There are some environment variables that you can set to change the behavior of
- `MAX_LATENCY`: The maximum latency to reach, default is 12000 (ms).

**consumer.sh:**
- `GRPC_SERVER`: The gRPC server to connect to, default is `host.docker.internal:8080`, connects to the host BlockNode.
- `GRPC_SERVER`: The gRPC server to connect to, default is `host.docker.internal:40840`, connects to the host BlockNode.
- `GRPC_METHOD`: The gRPC method to call, default is `BlockStreamGrpc/StreamSource`.
- `PATH_TO_PROTO`: The path to the proto file, default is `/usr/local/protos/blockstream.proto` (inside the container).
- `PROTO_IMPORT_PATH`: The import path of the proto file, default is `/usr/local/protos` (inside the container).

Example of how to set the environment variables when running the container:

```bash
docker run -it --cap-add=NET_ADMIN -e LATENCY_INCREASE_INTERVAL=5 -e INITIAL_LATENCY=1000 -e JITTER=1000 -e BANDWIDTH=128 -e INCREASE_TIME=5 -e MAX_LATENCY=10000 network-latency-simulator
```
2 changes: 1 addition & 1 deletion server/src/test/resources/consumer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ second_param="${2:-0}"
echo "Params are: $first_param, $second_param"

# Use environment variables or default values
GRPC_SERVER=${GRPC_SERVER:-"localhost:8080"}
GRPC_SERVER=${GRPC_SERVER:-"localhost:40840"}
GRPC_METHOD=${GRPC_METHOD:-"com.hedera.hapi.block.BlockStreamService/subscribeBlockStream"}
PATH_TO_PROTO="./block_service.proto"

Expand Down
2 changes: 1 addition & 1 deletion server/src/test/resources/get-block.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fi
echo "Param is: $1"

# Use environment variables or default values
GRPC_SERVER=${GRPC_SERVER:-"localhost:8080"}
GRPC_SERVER=${GRPC_SERVER:-"localhost:40840"}
GRPC_METHOD=${GRPC_METHOD:-"com.hedera.hapi.block.BlockAccessService/singleBlock"}
PATH_TO_PROTO="./block_service.proto"

Expand Down
2 changes: 1 addition & 1 deletion server/src/test/resources/producer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ generate_block_proof() {
echo "$result"
}

GRPC_SERVER="localhost:8080"
GRPC_SERVER="localhost:40840"
GRPC_METHOD="com.hedera.hapi.block.BlockStreamService/publishBlockStream"
PATH_TO_PROTO="./block_service.proto"

Expand Down
2 changes: 1 addition & 1 deletion server/src/test/resources/smoke-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ readiness() {
trap "shutdown; exit 1" ERR SIGINT SIGTERM

# 1. Call the endpoints /health/livez and /health/readyz
export SERVER_URL="http://localhost:8080"
export SERVER_URL="http://localhost:40840"
export LIVENESS_ENDPOINT="/healthz/livez"
export READINESS_ENDPOINT="/healthz/readyz"

Expand Down
44 changes: 22 additions & 22 deletions simulator/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,41 @@ There are 3 configuration sets:

Uses the prefix `blockStream` so all properties should start with `blockStream.`

| Key | Description | Default Value |
|:---|:---|---:|
| `simulatorMode` | The desired simulator mode to use, it can be either `PUBLISHER` or `CONSUMER`. | `PUBLISHER` |
| `delayBetweenBlockItems` | The delay between each block item in nanoseconds, only applicable when streamingMode=CONSTANT_RATE | `1_500_000` |
| `maxBlockItemsToStream` | exit condition for the simulator and the circular implementations such as `BlockAsDir` or `BlockAsFile` implementations | `10_000` |
| `streamingMode` | can either be `CONSTANT_RATE` or `MILLIS_PER_BLOCK` | `CONSTANT_RATE` |
| `millisecondsPerBlock` | if streamingMode is `MILLIS_PER_BLOCK` this will be the time to wait between blocks in milliseconds | `1_000` |
| `blockItemsBatchSize` | the number of block items to send in a single batch, however if a block has less block items, it will send all the items in a block | `1_000` |
| Key | Description | Default Value |
|:-------------------------|:------------------------------------------------------------------------------------------------------------------------------------|----------------:|
| `simulatorMode` | The desired simulator mode to use, it can be either `PUBLISHER` or `CONSUMER`. | `PUBLISHER` |
| `delayBetweenBlockItems` | The delay between each block item in nanoseconds, only applicable when streamingMode=CONSTANT_RATE | `1_500_000` |
| `maxBlockItemsToStream` | exit condition for the simulator and the circular implementations such as `BlockAsDir` or `BlockAsFile` implementations | `10_000` |
| `streamingMode` | can either be `CONSTANT_RATE` or `MILLIS_PER_BLOCK` | `CONSTANT_RATE` |
| `millisecondsPerBlock` | if streamingMode is `MILLIS_PER_BLOCK` this will be the time to wait between blocks in milliseconds | `1_000` |
| `blockItemsBatchSize` | the number of block items to send in a single batch, however if a block has less block items, it will send all the items in a block | `1_000` |

## GeneratorConfig

Uses the prefix `generator` so all properties should start with `generator.`

| Key | Description | Default Value |
|:---|:---|---:|
| `generationMode` | The desired generation Mode to use, it can only be `DIR` or `AD_HOC` | `DIR` |
| `folderRootPath` | If the generationMode is DIR this will be used as the source of the recording to stream to the Block-Node | `` |
| Key | Description | Default Value |
|:------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------:|
| `generationMode` | The desired generation Mode to use, it can only be `DIR` or `AD_HOC` | `DIR` |
| `folderRootPath` | If the generationMode is DIR this will be used as the source of the recording to stream to the Block-Node | `` |
| `managerImplementation` | The desired implementation of the BlockStreamManager to use, it can only be `BlockAsDirBlockStreamManager`, `BlockAsFileBlockStreamManager` or `BlockAsFileLargeDataSets` | `BlockAsFileBlockStreamManager` |
| `paddedLength` | on the `BlockAsFileLargeDataSets` implementation, the length of the padded left zeroes `000001.blk.gz` | 36 |
| `fileExtension` | on the `BlockAsFileLargeDataSets` implementation, the extension of the files to be streamed | `.blk.gz` |
| `paddedLength` | on the `BlockAsFileLargeDataSets` implementation, the length of the padded left zeroes `000001.blk.gz` | 36 |
| `fileExtension` | on the `BlockAsFileLargeDataSets` implementation, the extension of the files to be streamed | `.blk.gz` |

## GrpcConfig

Uses the prefix `grpc` so all properties should start with `grpc.`

| Key | Description | Default Value |
|:---|:---|---:|
| `serverAddress` | The host of the Block-Node | `localhost` |
| `port` | The port of the Block-Node | `8080` |
| Key | Description | Default Value |
|:----------------|:---------------------------|--------------:|
| `serverAddress` | The host of the Block-Node | `localhost` |
| `port` | The port of the Block-Node | `40840` |

## PrometheusConfig

Uses the prefix `prometheus` so all properties should start with `prometheus.`

| Key | Description | Default Value |
|:---|:---|--------------:|
| `endpointEnabled` | Whether Prometheus endpoint is enabled | `false` |
| `endpointPortNumber` | Port number for Prometheus endpoint | `9998` |
| Key | Description | Default Value |
|:---------------------|:---------------------------------------|--------------:|
| `endpointEnabled` | Whether Prometheus endpoint is enabled | `false` |
| `endpointPortNumber` | Port number for Prometheus endpoint | `9998` |
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
@ConfigData("grpc")
public record GrpcConfig(
@ConfigProperty(defaultValue = "localhost") String serverAddress,
@ConfigProperty(defaultValue = "8080") @Min(0) @Max(65535) int port) {}
@ConfigProperty(defaultValue = "40840") @Min(0) @Max(65535) int port) {}
4 changes: 2 additions & 2 deletions suites/src/main/java/com/hedera/block/suites/BaseSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ public static void teardown() {
*
* <ul>
* <li>Setting the environment variable "VERSION" from the .env file.
* <li>Exposing the default gRPC port (8080).
* <li>Exposing the default gRPC port (40840).
* <li>Using the Testcontainers health check mechanism to ensure the container is ready.
* </ul>
*
* @return a configured {@link GenericContainer} instance for the Block Node server
*/
protected static GenericContainer<?> createContainer() {
String blockNodeVersion = BaseSuite.getBlockNodeVersion();
blockNodePort = 8080;
blockNodePort = 40840;
List<String> portBindings = new ArrayList<>();
portBindings.add(String.format("%d:%2d", blockNodePort, blockNodePort));
blockNodeContainer = new GenericContainer<>(DockerImageName.parse("block-node-server:" + blockNodeVersion))
Expand Down
Loading