-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sample redis data pull scripts
- Loading branch information
Showing
14 changed files
with
793 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/.idea | ||
|
||
*/.idea | ||
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# [WIP] 3scale SaaS to RHOAM migration | ||
|
||
**WARNING:** The work that is on going here is for proof of concepts and should not be used on production systems. | ||
|
||
The redis_dump directory holds examples for how to pull metrics from redis on bulk. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM python:3.11 AS base | ||
RUN pip install --upgrade pip | ||
|
||
FROM base AS builder | ||
|
||
ENV POETRY_VERSION=1.1.13 | ||
|
||
RUN pip install "poetry==$POETRY_VERSION" | ||
|
||
WORKDIR /src | ||
|
||
COPY . /src/ | ||
RUN poetry build | ||
|
||
FROM base as runtime | ||
WORKDIR /app | ||
COPY --from=builder /src/dist/*.whl /app/ | ||
|
||
RUN pip install --no-cache-dir *.whl \ | ||
&& rm -rf *whl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# redis dump | ||
|
||
**WARNING:** These scripts are proof of concept and not complete. | ||
Please refer [MGDAPI-5322](https://issues.redhat.com/browse/MGDAPI-5322) for more information. | ||
|
||
This set of scripts is used to pull metrics from the 3scale redis and migrate them to a new instances. | ||
|
||
The scripts are design to be run as a pod on cluster. | ||
To run locally there are a number environment variables that need to be set. | ||
|
||
The best way to run them locally is by using podman. | ||
|
||
## Running Locally | ||
|
||
### Target Redis | ||
There needs to be access the target redis locally if using the default configuration. | ||
This can be done by setting up a port forward using `kubectl`. | ||
Personal I use `k9s` to manage this work but the command for `kubectl` would be something like: `kubectl port-forward <pod-name> <local port>:<remote port>`. | ||
The default configuration assumes the port to be `6379`. | ||
|
||
### Build the image | ||
From the project root run: | ||
|
||
```shell | ||
podman build -t redis_dump:latest . | ||
``` | ||
|
||
### Pull script | ||
Start the script by calling. | ||
```shell | ||
podman kube play --net=host pullfile.yaml | ||
``` | ||
|
||
Check pod logs for completion. | ||
```shell | ||
podman pod logs -f foobar | ||
``` | ||
|
||
Copy the json file form the container. | ||
```shell | ||
podman cp foobar-container:/app/data.json data.json | ||
``` | ||
|
||
Clean up the pods once finished. | ||
```shell | ||
podman kube down pullfile.yaml | ||
``` | ||
|
||
### Push script | ||
Start the script by calling. | ||
```shell | ||
podman kube play --net=host pushfile.yaml | ||
``` | ||
|
||
Check pod logs for completion. | ||
```shell | ||
podman pod logs -f foobar | ||
``` | ||
|
||
Clean up the pods once finished. | ||
```shell | ||
podman kube down pullfile.yaml | ||
``` | ||
|
||
### Seed Script | ||
The seed script is design to add volume to a redis instance for checking performances of other scripts. | ||
It is a test script and does not produce a 3scale usable redis instances. | ||
|
||
A local redis instance can be configured using the following. | ||
The volume is required if doing a large number of entries as the default container storage will fill. | ||
```shell | ||
podman volume create redisVol | ||
podman run --rm --name redis-server -p 6379:6379 -v redisVol:/data:z redis | ||
``` | ||
|
||
Set up the pod: | ||
```shell | ||
podman kube play --net=host --start=false seedfile.yaml | ||
``` | ||
|
||
Added the seed file. | ||
```shell | ||
podman cp seed.json foobar-container:/app/seed.json | ||
``` | ||
|
||
Start the pod. | ||
```shell | ||
podman pod start foobar | ||
``` | ||
|
||
Check logs for completed message. | ||
```shell | ||
podman pod logs -f foobar | ||
``` | ||
|
||
Clean the pod up once finished. | ||
```shell | ||
podman kube down seedfile.yaml | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: threescale-backend-redis-rhoam | ||
data: | ||
port: NjM3OQ== | ||
uri: bG9jYWxob3N0 | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: foo | ||
data: | ||
ACCOUNTS: "1,2,3,5,4,6,7" | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: foobar | ||
spec: | ||
containers: | ||
- command: | ||
- pull | ||
name: container | ||
image: redis_dump | ||
envFrom: | ||
- configMapRef: | ||
name: foo | ||
optional: false | ||
env: | ||
- name: PORT | ||
valueFrom: | ||
secretKeyRef: | ||
key: port | ||
name: threescale-backend-redis-rhoam | ||
- name: URI | ||
valueFrom: | ||
secretKeyRef: | ||
key: uri | ||
name: threescale-backend-redis-rhoam | ||
restartPolicy: Never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: threescale-backend-redis-rhoam | ||
data: | ||
port: NjM3OQ== | ||
uri: bG9jYWxob3N0 | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: foo | ||
data: | ||
ACCOUNTS: "1,2,3,5,4,6,7" | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: foobar | ||
spec: | ||
containers: | ||
- command: | ||
- push | ||
name: container | ||
image: redis_dump | ||
envFrom: | ||
- configMapRef: | ||
name: foo | ||
optional: false | ||
env: | ||
- name: PORT | ||
valueFrom: | ||
secretKeyRef: | ||
key: port | ||
name: threescale-backend-redis-rhoam | ||
- name: URI | ||
valueFrom: | ||
secretKeyRef: | ||
key: uri | ||
name: threescale-backend-redis-rhoam | ||
restartPolicy: Never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[tool.poetry] | ||
name = "redis_dump" | ||
version = "0.1.0" | ||
description = "" | ||
authors = ["Jim Fitzpatrick <[email protected]>"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.10" | ||
redis = "^4.5.4" | ||
|
||
[tool.poetry.dev-dependencies] | ||
pytest = "^5.2" | ||
|
||
[tool.poetry.scripts] | ||
pull = "redis_dump.main:pull" | ||
push = "redis_dump.main:push" | ||
seed = "redis_dump.main:seed" | ||
|
||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = '0.1.0' |
Oops, something went wrong.