National Dashboard Ingest

Overview

The objectives of the national dashboard-ingest service are listed below.

  1. To provide a one-stop framework for ingesting data regardless of a data source based on configuration.

  2. To create provision for ingest based on module-wise requirements which directly or indirectly require aggregated data ingestion functionality.

Pre-requisites

  1. Prior knowledge of Java/J2EE.

  2. Prior knowledge of SpringBoot.

  3. Prior knowledge of PostgreSQL.

  4. Prior knowledge of REST APIs and related concepts like path parameters, headers, JSON etc.

  5. Prior knowledge of ElasticSearch.

Setup & Key Functionalities

Setup

  1. Step 1: Define the index name for the module as per your requirement in module.index.mapping key present in the configuration here - DIGIT-DevOps/qa.yaml at master · egovernments/DIGIT-DevOps .

  2. Step 2: Define the allowed metrics for the module as per your requirement in module.fields.mapping key present in the configuration here - DIGIT-DevOps/qa.yaml at master · egovernments/DIGIT-DevOps

  3. Step 3: Define the allowed group-by fields for the module as per your requirement in module.allowed.groupby.fields.mapping key present in the configuration here - DIGIT-DevOps/qa.yaml at master · egovernments/DIGIT-DevOps

  4. Step 4: Define the master data index name as per your requirement in master.data.index key present in the configuration here - DIGIT-DevOps/qa.yaml at master · egovernments/DIGIT-DevOps

  5. Step 5: Define the allowed metrics for the master data index as per your requirement in master.module.fields.mapping key present in the configuration here - https://github.com/egovernments/DIGIT-DevOps/blob/master/deploy-as-code/helm/environments/qa.yaml#L367

  6. Step 6: Create Kafka connectors for all the modules that have been configured. A sample request for creating a trade license national dashboard Kafka connector is as follows -

curl --location --request POST 'http://kafka-connect.kafka-cluster:8083/connectors/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "cms-case-es-sink9128",
    "config": {
        "connector.class": "io.confluent.connect.elasticsearch.ElasticsearchSinkConnector",
        "connection.url": "http://elasticsearch-data-v1.es-cluster:9200/",
        "type.name": "nss",
        "topics": "tl-national-dashboard",
        "key.ignore": true,
        "schemas.enable": false,
        "schema.ignore": true,
        "value.converter.schemas.enable": false,
        "key.converter": "org.apache.kafka.connect.storage.StringConverter",
        "value.converter": "org.apache.kafka.connect.json.JsonConverter",
        "batch.size": 10,
        "max.buffered.records": 500,
        "flush.timeout.ms": 600000,
        "retry.backoff.ms": 5000,
        "read.timout.ms": 10000,
        "linger.ms": 100,
        "max.in.flight.requests": 2,
        "errors.log.enable": true,
        "errors.deadletterqueue.topic.name": "nss-es-failed",
        "tasks.max": 1
    }
}'

7. Step 7: Run the national-dashboard-ingest application along with the national-dashboard-ingest-kafka-pipeline.

Definitions

  1. Config file - A YAML (xyz.yml) file which contains configuration for running national dashboard ingest.

  2. API - A REST endpoint to post data based on the configuration.

Functionalities

  1. When the national dashboard ingests metrics API is hit, all the data payload lookup keys are first checked against the db to determine whether they already exist or not. The db table currently being used for storing lookup keys is nss-ingest-data.

  2. If the record for a given date and area details is not present, the payload is then flattened and pushed to nss-ingest-keydata topic.

  3. National dashboard ingest Kafka pipeline consumer listens on nss-ingest-keydata topic and according to the module to which the data belongs, pushes it to the respective topic defined in the module.index.mapping key.

  4. Once the national dashboard ingests the Kafka pipeline and pushes data to the respective topic, a Kafka connector then takes the flattened records from that topic and ingests into ElasticSearch.

Deployment Details

  1. Add configs for different modules required for National Dashboard Ingest Service and National Dashboard Kafka Pipeline service.

  2. Deploy the latest version of National Dashboard Ingest and National dashboard Kafka pipeline service.

  3. Add role-action mapping for APIs.

Integration Details

Integration Scope

The national dashboard service is used to push aggregated data present in systems and persisting them onto elasticsearch on top of which dashboards can be built for visualizing and analyzing data.

Integration Benefits

  • Can perform service-specific business logic without impacting the other module.

  • In the future, if we want to expose the application to citizens then it can be done easily.

Integration Steps

  1. To integrate, the host of the national-dashboard-ingest-service module should be overwritten in the helm chart.

  2. national-dashboard/metric/_ingest should be added as the search endpoint for the config added.

  3. national-dashboard/masterdata/_ingest should be added as the search endpoint for the config added.

API Details

URI: The format of the ingest API to be used to ingest data using national-dashboard-ingest is as follows: national-dashboard/metric/_ingest

Example ingest request body -

{
    "RequestInfo": {
        "apiId": "asset-services",
        "ver": null,
        "ts": null,
        "action": null,
        "did": null,
        "key": null,
        "msgId": "search with from and to values",
        "authToken": "82c7da0d-da73-4c35-8ea7-5b231369b4cd",
        "userInfo": {
        "id": 41737,
        "uuid": "9a81233f-e212-4035-a831-320b70e93b82",
        "userName": "NDSS1",
        "name": "National Dashboard Viewer",
        "mobileNumber": "7777888813",
        "emailId": null,
        "locale": null,
        "type": "EMPLOYEE",
        "roles": [
            {
                "name": "Employee",
                "code": "SUPERUSER",
                "tenantId": "pb.amritsar"
            },
            {
                "name": "National Dashboard Admin",
                "code": "NATADMIN",
                "tenantId": "pb.amritsar"
            },
            {
                "name": "FSM Employee Dashboard Viewer",
                "code": "FSM_DASHBOARD_VIEWER",
                "tenantId": "pb.amritsar"
            },
            {
                "name": "National Dashboard Admin",
                "code": "NATADMIN",
                "tenantId": "pb"
            }
        ],
        "active": true,
        "tenantId": "pb.amritsar",
        "permanentCity": null
    }
    },
    "Data": [
        {
        "date": "14-01-2017",
        "module": "MCOLLECT",
        "ward": "GODOWN AREA (BHABAT) - B14-SECTOR-13 - A1",
        "ulb": "pb.amritsar",
        "region": "Amritsar-MC",
        "state": "Punjab",
        "metrics": {
            "numberOfCategories": 240,
            "todaysCollection": [
                {
                    "groupBy": "paymentMode",
                    "buckets": [
                        {
                            "name": "UPI",
                            "value": 70
                        },
                        {
                            "name": "CASH",
                            "value": 45
                        },
                        {
                            "name": "DEBIT_CARD",
                            "value": 20
                        }
                    ]
                },
                {
                    "groupBy": "status",
                    "buckets": [
                        {
                            "name": "NEW",
                            "value": 70
                        },
                        {
                            "name": "DEPOSITED",
                            "value": 20
                        },
                        {
                            "name": "DISHONOURED",
                            "value": 45
                        }
                    ]
                },
                {
                    "groupBy": "category",
                    "buckets": [
                        {
                            "name": "COMMON_MASTERS_HOARDING",
                            "value": 50
                        },
                        {
                            "name": "COMMON_MASTERS_ROAD_SHOW",
                            "value": 20
                        },
                        {
                            "name": "COMMON_MASTERS_UNIPOLLS",
                            "value": 5
                        },
                        {
                            "name": "COMMON_MASTERS_AUCTION_FEE",
                            "value": 25
                        },
                        {
                            "name": "COMMON_MASTERS_USER_FEES",
                            "value": 35
                        }
                    ]
                }
            ],
            "numberOfReceipts": [
                {
                    "groupBy": "status",
                    "buckets": [
                        {
                            "name": "NEW",
                            "value": 70
                        },
                        {
                            "name": "DEPOSITED",
                            "value": 105
                        },
                        {
                            "name": "DISHONOURED",
                            "value": 50
                        }
                    ]
                },
                {
                    "groupBy": "paymentMode",
                    "buckets": [
                        {
                            "name": "CASH",
                            "value": 70
                        },
                        {
                            "name": "CHEQUE",
                            "value": 105
                        },
                        {
                            "name": "DEBIT_CARD",
                            "value": 35
                        },
                        {
                            "name": "ONLINE",
                            "value": 15
                        }
                    ]
                },
                {
                    "groupBy": "category",
                    "buckets": [
                        {
                            "name": "COMMON_MASTERS_HOARDING",
                            "value": 50
                        },
                        {
                            "name": "COMMON_MASTERS_ROAD_SHOW",
                            "value": 40
                        },
                        {
                            "name": "COMMON_MASTERS_UNIPOLLS",
                            "value": 45
                        },
                        {
                            "name": "COMMON_MASTERS_AUCTION_FEE",
                            "value": 55
                        },
                        {
                            "name": "COMMON_MASTERS_USER_FEES",
                            "value": 35
                        }
                    ]
                }
            ],
            "numberOfChallans": [
                {
                    "groupBy": "challanStatus",
                    "buckets": [
                        {
                            "name": "PAID",
                            "value": 50
                        },
                        {
                            "name": "CANCELLED",
                            "value": 105
                        },
                        {
                            "name": "ACTIVE",
                            "value": 35
                        }
                    ]
                },
                {
                    "groupBy": "category",
                    "buckets": [
                        {
                            "name": "COMMON_MASTERS_HOARDING",
                            "value": 50
                        },
                        {
                            "name": "COMMON_MASTERS_ROAD_SHOW",
                            "value": 40
                        },
                        {
                            "name": "COMMON_MASTERS_UNIPOLLS",
                            "value": 45
                        },
                        {
                            "name": "COMMON_MASTERS_AUCTION_FEE",
                            "value": 20
                        },
                        {
                            "name": "COMMON_MASTERS_USER_FEES",
                            "value": 35
                        }
                    ]
                }
            ]
        }
    }]
}

Module-wise Index Properties & Ingest Curls

The steps required for the creation of the index and adding the index mapping for the same can be found here - National Dashboard: Steps for Index Creation.

The following section contains module-wise index names, index mapping and ingest curls for ingesting data to national dashboard indexes.

1. Property Tax -

a. Index - pt-national-dashboard

b. Index mapping -

"properties" : {
          "assessedPropertiesForUsageCategory" : {
            "type" : "long"
          },
          "assessments" : {
            "type" : "long"
          },
          "cessForUsageCategory" : {
            "type" : "long"
          },
          "createdBy" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "createdTime" : {
            "type" : "long"
          },
          "date" : {
            "type" : "date",
            "format" : "dd-MM-yyyy HH:mm:ss||dd-MM-yyyy||epoch_millis||dd-MM-yyyy'T'HH:mm:ss.SSSZ"
          },
          "financialYear" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "interestForUsageCategory" : {
            "type" : "long"
          },
          "lastModifiedBy" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "lastModifiedTime" : {
            "type" : "long"
          },
          "module" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "penaltyForUsageCategory" : {
            "type" : "long"
          },
          "propertiesRegisteredForFinancialYear" : {
            "type" : "long"
          },
          "propertyTaxForUsageCategory" : {
            "type" : "long"
          },
          "rebateForUsageCategory" : {
            "type" : "long"
          },
          "region" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "state" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "todaysClosedApplications" : {
            "type" : "long"
          },
          "noOfPropertiesPaidToday" : {
            "type" : "long"
          },
          "todaysCollectionForUsageCategory" : {
            "type" : "long"
          },
          "todaysTotalApplications" : {
            "type" : "long"
          },
          "transactionsForUsageCategory" : {
            "type" : "long"
          },
          "ulb" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "usageCategory" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "ward" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }

c. Ingest curl -

curl --location --request POST 'https://qa.digit.org/national-dashboard/metric/_ingest' \
--header 'Content-Type: application/json' \
--data-raw '{
    "RequestInfo": {
        "apiId": "asset-services",
        "ver": null,
        "ts": null,
        "action": null,
        "did": null,
        "key": null,
        "msgId": "search with from and to values",
        "authToken": "null",
        "userInfo": {
            "id": 11131,
            "uuid": "0a8ef1d4-ef5c-4061-aea5-0ac4a410b87f",
            "userName": "NDSS",
            "name": "Lata",
            "mobileNumber": "7897807878",
            "emailId": null,
            "locale": null,
            "type": "EMPLOYEE",
            "roles": [
                {
                    "name": "National Dashboard Admin",
                    "code": "NATADMIN",
                    "tenantId": "pg"
                }
            ],
            "active": true,
            "tenantId": "uk.rishikesh",
            "permanentCity": null
        }
    },
    "Data": [
        {
            "date": "23-03-2022",
            "module": "PT",
            "ward": "Block 1",
            "ulb": "uk.rishikesh",
            "region": "Rishikesh-MC",
            "state": "Uttarakhand",
            "metrics": {
                "assessments": 29,
                "todaysTotalApplications": 62,
                "todaysClosedApplications": 21,
                "propertiesRegistered": [
                    {
                        "groupBy": "financialYear",
                        "buckets": [
                            {
                                "name": "2018-19",
                                "value": 12
                            },
                            {
                                "name": "2019-20",
                                "value": 18
                            },
                            {
                                "name": "2020-21",
                                "value": 21
                            }
                        ]
                    }
                ],
                "assessedProperties": [
                    {
                        "groupBy": "usageCategory",
                        "buckets": [
                            {
                                "name": "RESIDENTIAL",
                                "value": 21
                            },
                            {
                                "name": "COMMERCIAL",
                                "value": 11
                            },
                            {
                                "name": "INDUSTRIAL",
                                "value": 13
                            }
                        ]
                    }
                ],
                "transactions": [
                    {
                        "groupBy": "usageCategory",
                        "buckets": [
                            {
                                "name": "RESIDENTIAL",
                                "value": 19
                            },
                            {
                                "name": "COMMERCIAL",
                                "value": 13
                            },
                            {
                                "name": "INDUSTRIAL",
                                "value": 13
                            }
                        ]
                    }
                ],
                "todaysCollection": [
                    {
                        "groupBy": "usageCategory",
                        "buckets": [
                            {
                                "name": "RESIDENTIAL",
                                "value": 16000
                            },
                            {
                                "name": "COMMERCIAL",
                                "value": 22500
                            },
                            {
                                "name": "INDUSTRIAL",
                                "value": 26000
                            }
                        ]
                    }
                ],
                "propertyTax": [
                    {
                        "groupBy": "usageCategory",
                        "buckets": [
                            {
                                "name": "RESIDENTIAL",
                                "value": 1200
                            },
                            {
                                "name": "COMMERCIAL",
                                "value": 2100
                            },
                            {
                                "name": "INDUSTRIAL",
                                "value": 100
                            }
                        ]
                    }
                ],
                "cess": [
                    {
                        "groupBy": "usageCategory",
                        "buckets": [
                            {
                                "name": "RESIDENTIAL",
                                "value": 1300
                            },
                            {
                                "name": "COMMERCIAL",
                                "value": 1900
                            },
                            {
                                "name": "INDUSTRIAL",
                                "value": 1000
                            }
                        ]
                    }
                ],
                "rebate": [
                    {
                        "groupBy": "usageCategory",
                        "buckets": [
                            {
                                "name": "RESIDENTIAL",
                                "value": -500
                            },
                            {
                                "name": "COMMERCIAL",
                                "value": -1200
                            },
                            {
                                "name": "INDUSTRIAL",
                                "value": -900
                            }