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

Implement v1 of the healthcheck and create github files for open source #1

Merged
merged 37 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
51da304
Update template repository placeholders
kgapos Oct 24, 2023
b4c65f5
Add cspell spelling dictionary
kgapos Oct 24, 2023
976fa55
Add code owners file
kgapos Oct 24, 2023
3c75e64
Move github files to the .github directory
kgapos Oct 24, 2023
9f016c7
Update readme file
kgapos Oct 25, 2023
9f468e5
Add project logo
kgapos Oct 25, 2023
28ab570
Implement basic healthcheck
kgapos Oct 25, 2023
f7814b6
Add node hosting design diagram for the healthcheck system
kgapos Oct 25, 2023
2da0201
Add .gitignore file and ignore node_modules
kgapos Oct 25, 2023
c6d7a09
Add bash script to automate docker image releases
kgapos Oct 25, 2023
07df4a9
Update readme file with project specific information
kgapos Oct 25, 2023
4952501
Refactor CONTRIBUTING.md: Improve pull request section
kgapos Oct 25, 2023
199fd8b
Refactor build workflow and add SonarCloud analysis
kgapos Oct 25, 2023
b455ea5
Add build job with steps to install dependencies and build the project
kgapos Oct 25, 2023
a522911
Update build workflow to run the docker image and perform smoke test
kgapos Oct 25, 2023
b4e2e5b
Move source code to a new /src directory
kgapos Oct 25, 2023
30b7d46
Add buildx setup step in build workflow
kgapos Oct 25, 2023
ae53f7a
Remove package-lock.json file from the container
kgapos Oct 25, 2023
29be740
Use npm ci instead of npm install
kgapos Oct 25, 2023
2fbf516
Add QEMU dependency
kgapos Oct 25, 2023
311bdfe
Convert diagram to png due to limited github support for webp
kgapos Oct 26, 2023
6993e26
Move logo image to the images directory
kgapos Oct 26, 2023
365afb0
Update issue tracker links in the contributing file
kgapos Oct 26, 2023
b6673f8
Add details to the getting started section of the readme file
kgapos Oct 26, 2023
057c318
Default NODE_URL to mainnet.vechain.org
kgapos Oct 26, 2023
d12ebf8
Minor fixes
kgapos Oct 26, 2023
5b79765
Rename CODEOWNERS file
kgapos Oct 27, 2023
3afeb36
Add scripts to clean, build, run and test the app
kgapos Oct 27, 2023
20a7541
Update the build workflow to use the scripts
kgapos Oct 27, 2023
5432aa7
Apply 4 whitespace tabs and remove buildx/qemu from build workflow
kgapos Oct 27, 2023
3f11591
Update relative pathing
kgapos Oct 27, 2023
50759de
Restore buildx multi-arch process
kgapos Oct 27, 2023
889162c
Load the built image into docker
kgapos Oct 27, 2023
d4b3077
Security enhancements
kgapos Oct 28, 2023
ea3a4ee
Address sonar code smell
kgapos Oct 28, 2023
c339b58
Fix vechain casing in the readme file
kgapos Nov 2, 2023
1b628f4
Add more contact information
kgapos Nov 2, 2023
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@vechainfoundation/node-hosting-code-owners
18 changes: 10 additions & 8 deletions CODE_OF_CONDUCT.md → .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# [Project Name] Code of Conduct
Node Healthcheck Code of Conduct

## 1. Introduction

The [Project Name] community is dedicated to providing a welcoming, inclusive, and harassment-free environment for everyone, regardless of age, gender, gender identity and expression, sexual orientation, disability, physical appearance, body size, race, ethnicity, nationality, religion, or technical experience. This Code of Conduct outlines our expectations for all members of the [Project Name] community, as well as the consequences for unacceptable behavior.
The Node Healthcheck community is dedicated to providing a welcoming, inclusive, and harassment-free environment for everyone, regardless of age, gender, gender identity and expression, sexual orientation, disability, physical appearance, body size, race, ethnicity, nationality, religion, or technical experience. This Code of Conduct outlines our expectations for all members of the Node Healthcheck community, as well as the consequences for unacceptable behavior.

We invite all those who participate in [Project Name] to help us create a safe and positive environment for everyone.
We invite all those who participate in Node Healthcheck to help us create a safe and positive environment for everyone.

## 2. Expected Behavior

Expand Down Expand Up @@ -39,21 +39,23 @@ If a community member engages in unacceptable behavior, the community organizers

## 5. Reporting Guidelines

If you are subject to or witness unacceptable behavior, or have any other concerns, please notify a community organizer as soon as possible. You can contact the project maintainer at [[email protected]].

Additionally, community organizers are available to help community members engage with local law enforcement or to otherwise help those experiencing unacceptable behavior feel safe. In the context of in-person events, organizers will also provide escorts as desired by the person experiencing distress.
If you are subject to or witness unacceptable behavior, or have any other concerns, please [contact us](#8-contact-information) as soon as possible.

## 6. Addressing Grievances

If you feel you have been falsely or unfairly accused of violating this Code of Conduct, you should notify the project maintainer with a concise description of your grievance. Your grievance will be handled in accordance with our existing governing policies.
If you feel you have been falsely or unfairly accused of violating this Code of Conduct, you should [contact us](#8-contact-information) with a concise description of your grievance. Your grievance will be handled in accordance with our existing governing policies.

## 7. Scope

We expect all community participants (contributors, paid or otherwise; sponsors; and other guests) to abide by this Code of Conduct in all community venues--online and in-person--as well as in all one-on-one communications pertaining to community business.

## 8. Contact Information

You can contact the project maintainer at [[email protected]].
* Project maintainer [email protected]
* Project maintainer [email protected]
* Main contributor [email protected]
* Discord https://discord.com/invite/vechain #support
* Support https://support.vechain.org

## 9. License and Attribution

Expand Down
41 changes: 22 additions & 19 deletions CONTRIBUTING.md → .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,29 @@
# CONTRIBUTING to [Your Project Name]
# Contributing to Node Healthcheck

First of all, thank you for considering to contribute to [Your Project Name]! Your help is invaluable to improve the project and make it more useful for the community. This document will guide you through the contribution process and make it easier for you to get started.
First of all, thank you for considering to contribute to Node Healthcheck! Your help is invaluable to improve the project and make it more useful for the community. This document will guide you through the contribution process and make it easier for you to get started.

## Table of Contents

- [CONTRIBUTING to \[Your Project Name\]](#contributing-to-your-project-name)
- [Contributing to Node Healthcheck](#contributing-to-node-healthcheck)
- [Table of Contents](#table-of-contents)
- [Code of Conduct](#code-of-conduct)
- [Getting Started](#getting-started)
- [How to Contribute](#how-to-contribute)
- [Reporting Bugs](#reporting-bugs)
- [Suggesting Enhancements](#suggesting-enhancements)
- [Pull Requests](#pull-requests)
- [How to submit a pull request](#how-to-submit-a-pull-request)
- [Style Guide](#style-guide)
- [Additional Resources](#additional-resources)

## Code of Conduct

By participating in this project, you agree to abide by our [Code of Conduct](CODE_OF_CONDUCT.md). Please read it to ensure a welcoming and inclusive environment for all contributors.

## Getting Started

1. Fork the repository on GitHub.
2. Clone your fork to your local machine.
3. Create a new branch for your feature or bugfix.
1. Use `git checkout -b feature/your-feature-name` for features.
2. Use `git checkout -b bugfix/your-bugfix-name`) for bugfixes.
4. Make your changes and commit them to your new branch.
5. Push your changes to your fork.
6. Open a pull request against the main branch of the original repository.

## How to Contribute

### Reporting Bugs

If you find a bug, please create a new issue in the [issue tracker](https://github.com/vechainfoundation/your_project_name/issues). When submitting a bug report, please include:
If you find a bug, please create a new issue in the [issue tracker](https://github.com/vechainfoundation/node-healthcheck/issues). When submitting a bug report, please include:

- A clear and descriptive title.
- A detailed description of the issue, including the steps to reproduce the bug.
Expand All @@ -43,7 +32,7 @@ If you find a bug, please create a new issue in the [issue tracker](https://gith

### Suggesting Enhancements

If you have an idea for a new feature or improvement, please create a new issue in the [issue tracker](https://github.com/vechainfoundation/your_project_name/issues). When suggesting an enhancement, please include:
If you have an idea for a new feature or improvement, please create a new issue in the [issue tracker](https://github.com/vechainfoundation/node-healthcheck/issues). When suggesting an enhancement, please include:

- A clear and descriptive title.
- A detailed description of the proposed feature, including examples of how it should work.
Expand All @@ -60,11 +49,25 @@ If you would like to contribute code, documentation, or other assets to the proj
- Make sure your code passes any tests and linters that the project uses.
- Update any relevant documentation or comments.

#### How to submit a pull request

1. Fork the repository on GitHub.
2. Clone your fork to your local machine.
3. Create a new branch for your feature or bugfix based on the `main` branch.
1. Use `git checkout -b feature/your-feature-name` for features.
2. Use `git checkout -b bugfix/your-bugfix-name` for bugfixes.
4. Make your changes and commit them to your new branch.
5. Push your changes to your fork.
6. Open a pull request against the main branch of the original repository.

> :information_source: Tip:
> Write your commit messages following [the git guidelines](https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project). Use present tense and imperative verbs, e.g. "Fix bug" and not "Fixed bug" or "Fixes bug.". Your commit message should describe what the commit, when applied, does to the code – not what you did to the code.
## Style Guide

Please adhere to the project's coding style and conventions when contributing. This may include:

- Code formatting rules (e.g., indentation, line length, etc.).
- Code formatting (e.g., indentation, line length, etc.).
- Naming conventions for variables, functions, classes, etc.
- Commenting guidelines, including when and how to write comments.
- Test-writing guidelines, including test coverage requirements.
Expand All @@ -77,6 +80,6 @@ If the project uses a specific code formatter or linter, please ensure your cont
- [GitHub Help: Creating a pull request from a fork](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork)
- [Git Branching and Merging](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging)

Once again, thank you for your interest in contributing to [Your Project Name]! Your support and collaboration are crucial to the success and growth of this project. If you have any questions or need additional guidance, please don't hesitate to reach out to the maintainers.
Once again, thank you for your interest in contributing to Node Healthcheck! Your support and collaboration are crucial to the success and growth of this project. If you have any questions or need additional guidance, please don't hesitate to reach out to the maintainers.

Happy coding!
File renamed without changes.
129 changes: 129 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Node Healthcheck

![Node Hosting Project Logo](images/node-hosting.png)

## Introduction

This is a simple API that checks the health of a vechain node by comparing the timestamp of its latest block with the current time. If the timestamp is within an acceptable tolerance setting, it is considered healthy.

The main purpose of this tool is to be used in load balancers and availability monitors, to determine whether a node is not only online, but also fully synchronized with the blockchain. Moreover, it provides a `metrics` endpoint that is compatible with [prometheus](https://github.com/prometheus/prometheus) and exposes node health information to it.

The API contains two endpoints:

- `/healthcheck`

used by ALB to determine whether the node is online

- `/metrics`

used by Prometheus to collect health metrics, such as the last block timestamp, number of seconds since last block and node health status.

![Node Hosting Design Diagram - Healthcheck](images/architecture-diagram-healthcheck.webp)

## Table of Contents

- [Node Healthcheck](#node-healthcheck)
- [Introduction](#introduction)
- [Table of Contents](#table-of-contents)
- [Getting Started](#getting-started)
- [Configuration](#configuration)
- [NODE\_URL](#node_url)
- [NODE\_HEALTHCHECK\_PORT](#node_healthcheck_port)
- [NODE\_HEALTHCHECK\_TOLERANCE\_IN\_SECONDS](#node_healthcheck_tolerance_in_seconds)
- [Using Node](#using-node)
- [Using Docker](#using-docker)
- [Release new docker image](#release-new-docker-image)
- [Contributing](#contributing)
- [Roadmap](#roadmap)
- [Changelog](#changelog)
- [License](#license)
- [Credits](#credits)

## Getting Started

You can run the application with node, or in a container using docker.

### Configuration

You may override the default configuration by modifying the `.env` file.

#### NODE_URL

The URL of the node to be monitored by the healthcheck. Defaults to `https://node-test.vechain.org`

#### NODE_HEALTHCHECK_PORT

The port of the healthcheck API. Defaults to `11012`

#### NODE_HEALTHCHECK_TOLERANCE_IN_SECONDS

The amount of seconds before the healthcheck classifies the node as `unhealthy`. Defaults to `15`

### Using Node

To install and run the application with [node version 16.20.2](https://nodejs.org/dist/v16.20.2/), run the following commands in the root directory of the project:

```bash
cd src
npm ci
npm start
```

### Using Docker

To build and run the image with docker, run the following commands in the root directory of the project:

```bash
docker build . -t node-healthcheck:dev
docker run -d \
--name node-hc \
-p 11012:11012 \
-e NODE_URL=https://mainnet.vechain.org \
node-healthcheck:dev
```

To download and run the image with docker:

```bash
docker run -d \
--name node-hc \
-p 11012:11012 \
-e NODE_URL=https://mainnet.vechain.org \
public.ecr.aws/vechainfoundation/node-healthcheck:latest
```

For more image tags, refer to our [Container Registry](https://gallery.ecr.aws/vechainfoundation/node-healthcheck).

#### Release new docker image

To release a new version of the exporter, follow these steps:
1. If you haven't done so already, enable multi-architecture builds on your system:
1. Enable Docker BuildKit for multi-architecture builds by setting the environment variable in your shell profile: `export DOCKER_BUILDKIT=1`
2. Create Docker BuildKit builder on your system: `docker buildx create --use`
2. You will also need to have the AWS CLI installed and configured with credentials for ECR through profile `prod-node-devops`.
3. Run `./release.sh <version>` to build and push the image to ECR, where `<version>` is the tag for the new image.
4. Verify that the new release was correctly pushed to [the docker repository](https://gallery.ecr.aws/vechainfoundation/node-healthcheck).

### Contributing

If you want to contribute to this project and make it better, your help is very welcome. Contributing is also a great way to learn more about social coding on Github, new technologies and and their ecosystems and how to make constructive, helpful bug reports, feature requests and the noblest of all contributions: a good, clean pull request.

For more details and guidelines on how to contribute, refer to [CONTRIBUTING](CONTRIBUTING.md).

### Roadmap

We are planning to add more features to this application going forward. More details to follow and suggestions are always welcome in the form of [GitHub issues](https://docs.github.com/en/issues/tracking-your-work-with-issues/creating-an-issue).

### Changelog

- v1 [31-Mar-2023] Add prometheus metrics for node health
- v0 [08-Feb-2023] Implement a basic healthcheck API for nodes, based on block timestamps

### License

This project is licensed under [the MIT license](LICENSE.md).

### Credits

Special recognition to the main contributors:
- @fabiorigam
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/node-hosting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
gitleaks:
name: GitLeaks
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}

sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

build:
name: Build
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./scripts
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up QEMU dependency
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build docker image
run: ./build.sh
- name: Run docker image
run: ./run.sh
- name: Smoke test
run: ./test.sh
18 changes: 0 additions & 18 deletions .github/workflows/gitleaks.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/node_modules/*
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Build stage for amd64 architecture
FROM --platform=linux/amd64 node:gallium-alpine3.18 AS builder-amd64

WORKDIR /app
# Copy the package.json and package-lock.json to the container
COPY ./src/package*.json .
RUN npm ci --ignore-scripts
# Copy the rest of the application code to the container
COPY ./src .

# Build stage for arm64/v8 architecture
FROM --platform=linux/arm64/v8 node:gallium-alpine3.18 AS builder-arm64

WORKDIR /app
# Copy the package.json and package-lock.json to the container
COPY ./src/package*.json .
RUN npm ci --ignore-scripts
# Copy the rest of the application code to the container
COPY ./src .

# Production stage
FROM node:gallium-alpine3.18 AS runtime

RUN addgroup -S nonroot && adduser -S nonroot -G nonroot
WORKDIR /app

# Copy the files from the appropriate builder stage based on the target architecture
COPY --from=builder-amd64 /app /app
COPY --from=builder-arm64 /app /app
USER nonroot

# Set the default command to run when starting the container
CMD ["npm", "start"]
Loading