Solution Pattern: Sentiment Analysis

See the Solution in Action

1. Setup the Solution

To provision the demo you will perform the following steps - each of which are explained in detail in the next sections:

  • Gain access to Red Hat OpenShift. This solution pattern has been tested on OpenShift 4.13

  • Ensure you have the tools oc and ansible installed in your local environment such as your laptop

  • Access the OpenShift cluster with cluster-admin privileges

  • Log in to OpenShift with cluster-admin role via cli

  • Run the Ansible playbook

  • Run a bunch of scripts to deploy the Solution Pattern in your OpenShift cluster

1.1. Before getting started

Here is the list of tools you need in your local enviroment so that you can use the automated installation.

To check if you have the cli tools, you can open your terminal and use following commands:

oc version #openshift cli client
ansible --version
ansible-galaxy --version
ansible-galaxy collection list #the list should include kubernetes.core

If you can’t see kubernetes.core collection listed, you can install it with ansible-galaxy:

ansible-galaxy collection install kubernetes.core

1.2. Installing the demo

  • Login to your OpenShift cluster as cluster-admin (because a number of operators will need to be installed)

  • Click on the username on the top right hand, and then click on Copy login command. This will open another tab and you will need to login again

  • Click on Display token link, and copy the command under Log in with this token. This will look like this

oc login --token=<token> --server=<server>
  • Clone the ansible scripts as follows in an appropriate folder in your local environment

git clone https://github.com/rh-soln-pattern-sentiment-analysis/ansible
  • Navigate to the ansible folder

cd ansible
  • Run the ansible playbook as shown below. This will take a few minutes to complete. Ensure that the ansible playbook is deployed without errors

ansible-playbook playbooks/install.yml -e"ACTION=provision"
  • This is the output you get from the above ansible command:

PLAY RECAP ********************************************************************************************************************************************
localhost                  : ok=89   changed=21   unreachable=0    failed=0    skipped=25   rescued=0    ignored=0

That’s it! You are set to try out this Solution Pattern! 。◕‿◕。

2. Walkthrough guide

2.1. Explore the deployment on Red Hat OpenShift

There are 4 namespaces which are used for this Solution Pattern

  • sentiment-analysis:

    • most of the microservices

    • knative services, knative brokers, and knative triggers

  • influxdb-project:

    • InfluxDB - a time series database

    • Python based connector which reads from Kafka and pushes the content into InfluxDB

    • Grafana dashboard

  • globex: A number of fundamental microservices and database of the fictitious retail customer Globex, which are used in the our application, but aren’t really impacting the Sentiment Analysis solution pattern

  • globex-mw:

    • Red Hat AMQ Streams (Apache Kafka)

    • Kafdrop (a Kafka topic visualization tool)

  • rhsso:

    • Red Hat SSO based on Keycloak which manages the user login. You can find the password for the admin user within the Secret credential-rhsso within the rhsso namespace

2.2. Login to the Globex Web Application

  • Navigate the sentiment-analysis namespace and look for the globex-web-reviews deployment in the Developers perspective.

    sentiment analysis

  • Launch the globex-web-reviews app by clicking on the "launch arrow".

    • Alternatively the route can be fetched by running this command from your command line
      oc get route/globex-web-reviews -n sentiment-analysis

      launch globex

  • A number of users have been already setup for you

    • Choose any of these as login user names: asilva, mmiller, asanders, cjones or pwong

    • All users have the same password: openshift

  • Once you login, you can navigate to the Cool Stuff Store from the top menubar and click on any of the products to view the product details.

    coolstuff store

2.3. Review Moderation scenario

  • Type in a review comment - which is socially acceptable and not abusive - and submit the review.

    enter review

  • You will see a notification on the screen that the review has been submitted

    view review

  • Wait for a few seconds and the review would appear on the page - if your review was moderated as acceptable.

  • If you are adventurous, try one with abusive langage - not that we encourage this behaviour :) - but let’s put the system through its paces

    • You would notice that this review (ideally) will not appear on the screen.

Let us now trace the flow of the reviews across the various systems

  • The review gets submitted to the globex.reviews kafka topic, which then gets picked up by the Intelligent App aiml-moderate-reviews

    • This service routes the reviews to either reviews.moderated topic or reviews.denied topic depending on whether review’s language was acceptable or not

      aiml moderate reviews app

  • You can view these topics through Kafkdrop. To access Kafdrop, navigate to globex-mw namespace, and launch kafdrop.

  • Filter the topics with the word review to see a list of relevant topics

    reviews topics

  • Click on each of the topics to see the actual messages.

  • This is the reviews.moderated topic. You will notice that the message is a JSON.

    • What is even more interesting is the headers of this message ce-type and ce-source

    • These headers are present because the messages are all managed as Cloud Events. CloudEvents is a specification for describing event data in a common way.

      moderated review

2.4. Sentiment Analysis scenario

  • To access the Grafana Dashboard, navigatein your OpenShift cluster, navigate to Networking > Routes.

  • Filter with Name as grafana and click on the URL that is displayed under Location

    grafana url

  • Login using admin/graphsRcool

    grafana login

  • Click on left-hand menu, and click on Dashboards Now click on the General folder displayed

    • This will show a link to GLOBEX Sentiment Analysis Dashboard. Click on this to launch the Dashboard

      grafana landing

  • Navigate to the Globex Sentiment Analysis Dashboard

You will see a couple of data there from the reviews you had submitted in the previous step - nothing much to talk about! Yet…​..

Let’s use a simulator to submit a number of reviews to see some serious stuff!! \m/

  • Navigate back to the sentiment-analysis namespace in OpenShift console and look for the reviews-simulator deployment and launch it.

    reviews simulator

  • This is deployed as a knative service with zero replica. So you can see a pod getting created as soon as you launch it.

  • Click on the POST, and then the Try it out button.

  • Choose the Clothing Catalogue option, and click Execute. A number of random reviews are generated for you.

    simulate clothing reviews

  • Go ahead and try out the Bags option as well!

  • Give it a go a few more times maybe

Alright.. Let’s go check out the Grafana Dashboard..

  • You can view a doughnut shaped chart right on top of the page showing the breakup of the overall sentiment across Globex.

  • Right below this, you will also see the charts showing the sentiment analysis breakup for Clothing and Bags.

    clothing dashboard
  • You can duplicate these charts with other Catalogues as well. Here is a list of all of the possible catalogues

    • clothing

    • bags

    • utensils

    • office supplies

    • fashion accessory

    • electronics

    • sports equipment

  • You can generate more reviews for the Bags Catalogue using the simulator to view more data on the dashboard.

    bag dashboard

  • You can also view the Tabular Data of the Bags and Clothing catalogues

    tabular data

Well done! You have come to the end of the demo. You can have a look at all this code here: https://github.com/rh-soln-pattern-sentiment-analysis

Errors? Issues? Feel free to submit questions or file a bug. And you are welcome to contribute too ツ

All the container images are here: https://quay.io/organization/globex-sentiment-analysis