Skip to content

Dev environment setup (local)

Shivam Deotarse edited this page Nov 2, 2023 · 6 revisions

Installation

Download and install Go

ros-ocp-backend is written in go 1.19. To download go run below commands below steps.

# wget https://go.dev/dl/go1.19.5.linux-amd64.tar.gz
# sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.19.5.linux-amd64.tar.gz
# sudo echo "export PATH=$PATH:/usr/local/go/bin"  >> /etc/profile
# source /etc/profile
# go version

Clone the repository

# git clone https://github.com/RedHatInsights/ros-ocp-backend.git

Update /etc/hosts

127.0.0.1       kafka
127.0.0.1       minio

Install librdkafka and librdkafka-devel packages

# dnf install -y librdkafka librdkafka-devel

Usage

Run dependent services

ros-ocp-backend dependence on few services like Kafka, Ingress, Kruize etc. Before starting ros-ocp-backend we first need to start all other services inside docker container.

# cd scripts
# docker-compose up

Note - If you are unable to pull image from quay.io then try to login quay.io using docker login quay.io and run docker-compose up again.

Start ROS-OCP-Backend

# make db-migrate
# make run-processor

Sending data to local ros-ocp-backend

# make upload-msg-to-rosocp

Watch the kafka consumer for a message to arrive

# docker-compose exec kafka kafka-console-consumer --topic=platform.upload.rosocp --bootstrap-server=localhost:29092

You will see something like this in the consumer terminal.

{"request_id": "uuid1234", "b64_identity": "test", "metadata": {"account": "123", "org_id": "345", "source_id": "111", "cluster_id": "222"}, "files": ["http://s3.amazonaws.com/bucket_name/rosocp/ros-usage.csv"]}

Instead of using make upload-msg-to-rosocp one can send a custom json message to platform.upload.rosocp with the help of kafka-console-producer using the below command.

# docker-compose exec kafka kafka-console-producer --topic platform.upload.rosocp  --broker-list localhost:29092

Get recommendations

To get recommendations after sending data to local ros-ocp-backend use below command.

# make get-recommendations start_date=<YYYY-MM-DD>

else default start_date = 1970-01-01 Epoch date used in UNIX and POSIX systems

Testing and Linting

ROS-OCP uses golangci-lint for code linting:

# make lint

For running unit tests use below command

# make test

Submitting Patches

Patches to fix bugs or add new features are always appreciated. If you are going to work on a specific issue, make sure github issue OR JIRA issue ticket is open for the change you are going to submit.

  1. Create a fork of ros-ocp-backend repo in your github account

  2. Create a feature/topic branch

    # git checkout -b <branchName>
  3. Make changes and commit. Please reference the issue number this commit addresses via “Refs” or “Fixes” in the commit message.

    # git add <modifiedFile(s)>
    # git commit -m 'Fixes #<bug> - <message>'
  4. Push topic branch to your fork

    # git push origin <branchName>
  5. Issue a pull request