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

exp/services/ledgerexporter: create go integration tests for sub commands #5370

Merged
merged 18 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6848f23
hubble-469: create go integration tests for ledger exporter sub comma…
sreuland Jul 3, 2024
84db385
Merge remote-tracking branch 'upstream/master' into lexie_int_test
sreuland Jul 3, 2024
7f0f1e0
hubble-469: use fully qualified docker.io url
sreuland Jul 3, 2024
31e2255
hubble-469: pull docker image in gha step on le ci
sreuland Jul 3, 2024
17ce7fe
hubble-469: pull docker image in gha step on le release ci
sreuland Jul 3, 2024
1bb82f5
#hubble-469: moved integration test docs to developer guide
sreuland Jul 3, 2024
0d3a999
#hubble-469: fixed docker image pull
sreuland Jul 3, 2024
0300ed6
#hubble-469: fix typo, review feedback
sreuland Jul 3, 2024
9167c22
Update .github/workflows/ledgerexporter-release.yml, review feedback
sreuland Jul 3, 2024
c75d993
#hubble-469: bring the fake gcs make target back in, review feedback
sreuland Jul 3, 2024
9374cf3
#hubble-469: fixed docker pull aspects, use temp dir for ccore storag…
sreuland Jul 5, 2024
4dd77b9
#hubble-469: fix govet warn
sreuland Jul 5, 2024
4cdb5b9
#hubble-469: fix unit test for flags, change captive core config on i…
sreuland Jul 5, 2024
eb27809
#hubble-469: removed debugging code
sreuland Jul 5, 2024
eb1976a
#hubble-469: fixing captive core peer port collsion with quickstart s…
sreuland Jul 5, 2024
87fb038
hubble-469: start quickstart with '--limits default' to disable unnee…
sreuland Jul 5, 2024
bba71e6
#hubble-469: fix gofmt warn
sreuland Jul 5, 2024
f45234c
#hubble-469: use fully qualified ENABLE settig for quickstart
sreuland Jul 8, 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
1 change: 0 additions & 1 deletion .github/workflows/horizon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,3 @@ jobs:
- if: github.ref == 'refs/heads/master'
name: Push to DockerHub
run: docker push stellar/horizon-verify-range:latest

31 changes: 27 additions & 4 deletions .github/workflows/ledgerexporter-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,40 @@ jobs:
name: Test and push the Ledger Exporter images
runs-on: ubuntu-latest
env:
LEDGEREXPORTER_INTEGRATION_TESTS_ENABLED: "true"
LEDGEREXPORTER_INTEGRATION_TESTS_CAPTIVE_CORE_BIN: /usr/bin/stellar-core
# this pins to a version of quickstart:testing that has the same version as STELLAR_CORE_VERSION
# this is the multi-arch index sha, get it by 'docker buildx imagetools inspect stellar/quickstart:testing'
LEDGEREXPORTER_INTEGRATION_TESTS_QUICKSTART_IMAGE: docker.io/stellar/quickstart:testing@sha256:03c6679f838a92b1eda4cd3a9e2bdee4c3586e278a138a0acf36a9bc99a0041f
LEDGEREXPORTER_INTEGRATION_TESTS_QUICKSTART_IMAGE_PULL: "false"
STELLAR_CORE_VERSION: 21.1.0-1921.b3aeb14cc.focal
VERSION: ${GITHUB_REF_NAME#ledgerexporter-v}
VERSION: ${GITHUB_REF_NAME#ledgerexporter-v}
steps:
- uses: actions/checkout@v3
with:
ref: github.sha
- name: Build Ledger Exporter docker
run: make -C exp/services/ledgerexporter docker-build
- name: Pull Quickstart image
shell: bash
run: |
docker pull "$LEDGEREXPORTER_INTEGRATION_TESTS_QUICKSTART_IMAGE"
- name: Install captive core
run: |
# Workaround for https://github.com/actions/virtual-environments/issues/5245,
# libc++1-8 won't be installed if another version is installed (but apt won't give you a helpul
# message about why the installation fails)
sudo apt list --installed | grep libc++
sudo apt-get remove -y libc++1-* libc++abi1-* || true

sudo wget -qO - https://apt.stellar.org/SDF.asc | APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=true sudo apt-key add -
sudo bash -c 'echo "deb https://apt.stellar.org focal unstable" > /etc/apt/sources.list.d/SDF-unstable.list'
sudo apt-get update && sudo apt-get install -y stellar-core="$STELLAR_CORE_VERSION"
echo "Using stellar core version $(stellar-core version)"

- name: Run Ledger Exporter test
run: make -C exp/services/ledgerexporter docker-test
run: go test -v -race -run TestLedgerExporterTestSuite ./exp/services/ledgerexporter/...

- name: Build Ledger Exporter docker
run: make -C exp/services/ledgerexporter docker-build

# Push images
- name: Login to DockerHub
Expand Down
35 changes: 28 additions & 7 deletions .github/workflows/ledgerexporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,39 @@ on:

jobs:
ledger-exporter:
name: Build and test Ledger Exporter image
name: Test Ledger Exporter
runs-on: ubuntu-latest
env:
STELLAR_CORE_VERSION: 21.1.0-1921.b3aeb14cc.focal
CAPTIVE_CORE_DEBIAN_PKG_VERSION: 21.1.0-1921.b3aeb14cc.focal
LEDGEREXPORTER_INTEGRATION_TESTS_ENABLED: "true"
LEDGEREXPORTER_INTEGRATION_TESTS_CAPTIVE_CORE_BIN: /usr/bin/stellar-core
# this pins to a version of quickstart:testing that has the same version as LEDGEREXPORTER_INTEGRATION_TESTS_CAPTIVE_CORE_BIN
# this is the multi-arch index sha, get it by 'docker buildx imagetools inspect stellar/quickstart:testing'
LEDGEREXPORTER_INTEGRATION_TESTS_QUICKSTART_IMAGE: docker.io/stellar/quickstart:testing@sha256:03c6679f838a92b1eda4cd3a9e2bdee4c3586e278a138a0acf36a9bc99a0041f
LEDGEREXPORTER_INTEGRATION_TESTS_QUICKSTART_IMAGE_PULL: "false"
steps:
- name: Install captive core
run: |
# Workaround for https://github.com/actions/virtual-environments/issues/5245,
# libc++1-8 won't be installed if another version is installed (but apt won't give you a helpul
# message about why the installation fails)
sudo apt list --installed | grep libc++
sudo apt-get remove -y libc++1-* libc++abi1-* || true

sudo wget -qO - https://apt.stellar.org/SDF.asc | APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=true sudo apt-key add -
sudo bash -c 'echo "deb https://apt.stellar.org focal unstable" > /etc/apt/sources.list.d/SDF-unstable.list'
sudo apt-get update && sudo apt-get install -y stellar-core="$CAPTIVE_CORE_DEBIAN_PKG_VERSION"
echo "Using stellar core version $(stellar-core version)"

- name: Pull Quickstart image
shell: bash
run: |
docker pull "$LEDGEREXPORTER_INTEGRATION_TESTS_QUICKSTART_IMAGE"

- uses: actions/checkout@v3
with:
# For pull requests, build and test the PR head not a merge of the PR with the destination.
ref: ${{ github.event.pull_request.head.sha || github.ref }}
- name: Build Ledger Exporter docker
run: make -C exp/services/ledgerexporter docker-build


- name: Run Ledger Exporter test
run: make -C exp/services/ledgerexporter docker-test

run: go test -v -race -run TestLedgerExporterTestSuite ./exp/services/ledgerexporter/...
21 changes: 19 additions & 2 deletions exp/services/ledgerexporter/DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,31 @@ To achieve its goals, the ledger exporter uses the following architecture, which
- An example implementation of `DataStore` for GCS, Google Cloud Storage. This plugin is located in the [support](https://github.com/stellar/go/tree/master/support/datastore) package.
- The ledger exporter currently implements the interface only for Google Cloud Storage (GCS). The [GCS plugin](https://github.com/stellar/go/blob/master/support/datastore/gcs_datastore.go) uses GCS-specific behaviors like conditional puts, automatic retry, metadata, and CRC checksum.

## Build, Run and Test using Docker
## Build and Run using Docker
The Dockerfile contains all the necessary dependencies (e.g., Stellar-core) required to run the ledger exporter.

- Build: To build the Docker container, use the provided [Makefile](./Makefile). Simply run make `make docker-build` to build a new container after making any changes.

- Run: For instructions on running the Docker container, refer to the [Installation Guide](./README.md).

- Test: To test the Docker container, refer to the [docker-test](./Makefile) command for an example of how to use the [GCS emulator](https://github.com/fsouza/fake-gcs-server) for local testing.
urvisavla marked this conversation as resolved.
Show resolved Hide resolved
- Run ledgerexporter with a local, fake GCS backend: Requires `make docker-build` first, then run `make docker-test-fake-gcs`. This will run the ledger exporter against `testnet` and export to the 'fake' GCS instance started in the container.

## Running Integration Tests:
from top directory of stellar/go repo, run go test to launch ledger exporter integration
tests.

`LEDGEREXPORTER_INTEGRATION_TESTS_ENABLED=true` is required environment variable to allow
tests to run.

Optional, tests will try to run `stellar-core` from o/s PATH for captive core, if not resolvable, then set `LEDGEREXPORTER_INTEGRATION_TESTS_CAPTIVE_CORE_BIN=/path/to/stellar-core`

Optional, can override the version of quickstart used to run standalone stellar network, `LEDGEREXPORTER_INTEGRATION_TESTS_QUICKSTART_IMAGE=docker.io/stellar/quickstart:<tag>`. By default it will try to docker pull `stellar/quickstart:testing` image to local host's docker image store. Set `LEDGEREXPORTER_INTEGRATION_TESTS_QUICKSTART_IMAGE_PULL=false` to skip the pull, if you know host has up to date image.

Note, the version of stellar core in `LEDGEREXPORTER_INTEGRATION_TESTS_QUICKSTART_IMAGE` and `LEDGEREXPORTER_INTEGRATION_TESTS_CAPTIVE_CORE_BIN` needs to be on the same major rev or the captive core process may not be able to join or parse ledger meta from the `local` network created by `LEDGEREXPORTER_INTEGRATION_TESTS_QUICKSTART_IMAGE`

```
$ LEDGEREXPORTER_INTEGRATION_TESTS_ENABLED=true go test -v -race -run TestLedgerExporterTestSuite ./exp/services/ledgerexporter/...
```

## Adding support for a new storage type
Support for different data storage types are encapsulated as 'plugins', which are implementation of `DataStore` interface in a go package. To add a data storage plugin based on a new storage type (e.g. AWS S3), follow these steps:
Expand Down
2 changes: 1 addition & 1 deletion exp/services/ledgerexporter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ docker-clean:
$(SUDO) rm -rf ${PWD}/storage || true
$(SUDO) docker network rm test-network || true

docker-test: docker-clean
sreuland marked this conversation as resolved.
Show resolved Hide resolved
docker-test-fake-gcs: docker-clean
# Create temp storage dir
$(SUDO) mkdir -p ${PWD}/storage/exporter-test

Expand Down
3 changes: 1 addition & 2 deletions exp/services/ledgerexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,4 @@ docker run --platform linux/amd64 -d \
Arguments:
- `--start <start_ledger>` (required): The starting ledger sequence number in the range to export.
- `--end <end_ledger>` (required): The ending ledger sequence number in the range.
- `--config-file <config_file_path>` (optional): The path to your configuration file, containing details like GCS bucket information. If not provided, the exporter will look for config.toml in the directory where you run the command.

- `--config-file <config_file_path>` (optional): The path to your configuration file, containing details like GCS bucket information. If not provided, the exporter will look for config.toml in the directory where you run the command.
2 changes: 1 addition & 1 deletion exp/services/ledgerexporter/internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func newAdminServer(adminPort int, prometheusRegistry *prometheus.Registry) *htt
}

func (a *App) Run(runtimeSettings RuntimeSettings) error {
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(runtimeSettings.Ctx)
defer cancel()

if err := a.init(ctx, runtimeSettings); err != nil {
Expand Down
14 changes: 11 additions & 3 deletions exp/services/ledgerexporter/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type RuntimeSettings struct {
EndLedger uint32
ConfigFilePath string
Mode Mode
Ctx context.Context
}

type StellarCoreConfig struct {
Expand All @@ -56,6 +57,8 @@ type StellarCoreConfig struct {
HistoryArchiveUrls []string `toml:"history_archive_urls"`
StellarCoreBinaryPath string `toml:"stellar_core_binary_path"`
CaptiveCoreTomlPath string `toml:"captive_core_toml_path"`
CheckpointFrequency uint32 `toml:"checkpoint_frequency"`
StoragePath string `toml:"storage_path"`
}

type Config struct {
Expand Down Expand Up @@ -98,8 +101,8 @@ func NewConfig(settings RuntimeSettings, getCoreVersionFn ledgerbackend.CoreBuil
}
logger.Infof("Network Config Archive URLs: %v", config.StellarCoreConfig.HistoryArchiveUrls)
logger.Infof("Network Config Archive Passphrase: %v", config.StellarCoreConfig.NetworkPassphrase)
logger.Infof("Network Config Archive Stellar Core Binary Path: %v", config.StellarCoreConfig.StellarCoreBinaryPath)
logger.Infof("Network Config Archive Stellar Core Toml Config: %v", string(config.SerializedCaptiveCoreToml))
logger.Infof("Network Config Stellar Core Binary Path: %v", config.StellarCoreConfig.StellarCoreBinaryPath)
logger.Infof("Network Config Stellar Core Toml Config: %v", string(config.SerializedCaptiveCoreToml))

return config, nil
}
Expand Down Expand Up @@ -185,15 +188,20 @@ func (config *Config) GenerateCaptiveCoreConfig(coreBinFromPath string) (ledgerb
return ledgerbackend.CaptiveCoreConfig{}, errors.Wrap(err, "Failed to create captive-core toml")
}

checkpointFrequency := historyarchive.DefaultCheckpointFrequency
if config.StellarCoreConfig.CheckpointFrequency > 0 {
checkpointFrequency = config.StellarCoreConfig.CheckpointFrequency
}
return ledgerbackend.CaptiveCoreConfig{
BinaryPath: config.StellarCoreConfig.StellarCoreBinaryPath,
NetworkPassphrase: params.NetworkPassphrase,
HistoryArchiveURLs: params.HistoryArchiveURLs,
CheckpointFrequency: historyarchive.DefaultCheckpointFrequency,
CheckpointFrequency: checkpointFrequency,
Log: logger.WithField("subservice", "stellar-core"),
Toml: captiveCoreToml,
UserAgent: "ledger-exporter",
UseDB: true,
StoragePath: config.StellarCoreConfig.StoragePath,
}, nil
}

Expand Down
Loading
Loading