Rosiberto
Rosiberto

Reputation: 83

Problem when querying Raw Data with STH-Comet - Returns empty

I have Orion, Cygnus and STH-Comet(installed and configured in formal mode). Each component is in a container docker. I implemented the infrastructure with docker-compose.yml.

The Cygnus container is configured as follows:

    image: fiware/cygnus-ngsi:latest
    hostname: cygnus
    container_name: cygnus
    volumes:
      - /home/ubuntu/cygnus/multisink_agent.conf:/opt/fiware-cygnus/docker/cygnus-ngsi/multisink_agent.conf
    depends_on:
      - mongo
    networks:
      - default
    expose:
      - "5050"
      - "5080"
    ports:
      - "5050:5050"
      - "5080:5080" 
    environment:
      - CYGNUS_SERVICE_PORT=5050
      - CYGNUS_MONITORING_TYPE=http
      - CYGNUS_AGENT_NAME=cygnus-ngsi
      - CYGNUS_MONGO_SERVICE_PORT=5050
      - CYGNUS_MONGO_HOSTS=mongo:27017
      - CYGNUS_MONGO_USER=
      - CYGNUS_MONGO_PASS=
      - CYGNUS_MONGO_ENABLE_ENCODING=false
      - CYGNUS_MONGO_ENABLE_GROUPING=false
      - CYGNUS_MONGO_ENABLE_NAME_MAPPINGS=false
      - CYGNUS_MONGO_DATA_MODEL=dm-by-entity
      - CYGNUS_MONGO_ATTR_PERSISTENCE=column
      - CYGNUS_MONGO_DB_PREFIX=sth_
      - CYGNUS_MONGO_COLLECTION_PREFIX=sth_   
      - CYGNUS_MONGO_ENABLE_LOWERCASE=false
      - CYGNUS_MONGO_BATCH_TIMEOUT=30
      - CYGNUS_MONGO_BATCH_TTL=10
      - CYGNUS_MONGO_DATA_EXPIRATION=0
      - CYGNUS_MONGO_COLLECTIONS_SIZE=0
      - CYGNUS_MONGO_MAX_DOCUMENTS=0
      - CYGNUS_MONGO_BATCH_SIZE=1
      - CYGNUS_LOG_LEVEL=DEBUG
      - CYGNUS_SKIP_CONF_GENERATION=false 
      - CYGNUS_STH_ENABLE_ENCODING=false
      - CYGNUS_STH_ENABLE_GROUPING=false
      - CYGNUS_STH_ENABLE_NAME_MAPPINGS=false
      - CYGNUS_STH_DB_PREFIX=sth_
      - CYGNUS_STH_COLLECTION_PREFIX=sth_
      - CYGNUS_STH_DATA_MODEL=dm-by-entity
      - CYGNUS_STH_ENABLE_LOWERCASE=false
      - CYGNUS_STH_BATCH_TIMEOUT=30
      - CYGNUS_STH_BATCH_TTL=10
      - CYGNUS_STH_DATA_EXPIRATION=0
      - CYGNUS_STH_BATCH_SIZE=1

Obs: In the multisink_agent.conf file I changed the service and the servicepath:

cygnus-ngsi.sources.http-source-mongo.handler.default_service = tese

cygnus-ngsi.sources.http-source-mongo.handler.default_service_path = /iot

And the STH-Comet container looks like this:

    image: fiware/sth-comet:latest
    hostname: sth
    container_name: sth
    depends_on:
      - cygnus
      - mongo
    networks:
      - default
    expose:
      - "8666"
    ports:
      - "8666:8666"
    environment:
      - STH_HOST=0.0.0.0
      - STH_PORT=8666
      - DB_URI=mongo:27017
      - DB_USERNAME=
      - DB_PASSWORD=
      - LOGOPS_LEVEL=DEBUG

In the STH-Comet config.js file I enabled CORS and I changed the defaultService and the defaultServicePath. The file looks like this:

var config = {};

// STH server configuration
//--------------------------
config.server = {
    host: 'localhost',
    port: '8666',
    // Default value: "testservice".
    defaultService: 'tese',
    // Default value: "/testservicepath".
    defaultServicePath: '/iot',
    filterOutEmpty: 'true',
    aggregationBy: ['day', 'hour', 'minute'],
    temporalDir: 'temp',
    maxPageSize: '100'
};

// Cors Configuration
config.cors = {
    // The enabled is use to set CORS policy
    enabled: 'true',
    options: {
        origin: ['*'],
        headers: [
            'Access-Control-Allow-Origin',
            'Access-Control-Allow-Headers',
            'Access-Control-Request-Headers',
            'Origin, Referer, User-Agent'
        ],
        additionalHeaders: ['fiware-servicepath', 'fiware-service'],
        credentials: 'true'
    }
};

// Database configuration
//------------------------
config.database = {
    dataModel: 'collection-per-entity',
    user: '',
    password: '',
    authSource: '',
    URI: 'localhost:27017',
    replicaSet: '',
    prefix: 'sth_',
    collectionPrefix: 'sth_',
    poolSize: '5',
    writeConcern: '1',
    shouldStore: 'both',
    truncation: {
        expireAfterSeconds: '0',
        size: '0',
        max: '0'
    },
    ignoreBlankSpaces: 'true',
    nameMapping: {
        enabled: 'false',
        configFile: './name-mapping.json'
    },
    nameEncoding: 'false'
};

// Logging configuration
//------------------------
config.logging = {
   
    level: 'debug',
    format: 'pipe',
    proofOfLifeInterval: '60',
    processedRequestLogStatisticsInterval: '60'
};

module.exports = config;

I use Cygnus to persist historical data. STH-Comet is used only to query raw and aggregated data.

Cygnus' signature on Orion did this:

  "description": "A subscription All Entities",
  "subject": {
    "entities": [
      {
        "idPattern": ".*"
      }
    ],
    "condition": {
      "attrs": []
    }
  },
  "notification": {
    "http": {
      "url": "http://cygnus:5050/notify"
    },
    "attrs": [],
    "attrsFormat":"legacy"
  },
  "expires": "2040-01-01T14:00:00.00Z",
  "throttling": 5
}

The headers used for fiware-service and fiware-servicepath are:

Fiware-service: tese

Fiware-servicepath: /iot

The entities data are stored in orion-tese. I have the collection: entities

{
        "_id" : {
                "id" : "Tank1",
                "type" : "Tank",
                "servicePath" : "/iot"
        },
        "attrNames" : [
                "temperature"
        ],
        "attrs" : {
                "temperature" : {
                        "value" : 0.333,
                        "type" : "Float",
                        "mdNames" : [ ],
                        "creDate" : 1594334464,
                        "modDate" : 1594337770
                }
        },
        "creDate" : 1594334464,
        "modDate" : 1594337771,
        "lastCorrelator" : "f86d0d74-c23c-11ea-9c82-0242ac1c0005"
}

The raw and aggregated data are stored in sth_tese. I have the collections:

sth_/iot_Tank1_Tank.aggr

and

sth_/iot_Tank1_Tank

The sth_/iot_Tank1_Tank raw data is in mongoDB:

{
        "_id" : ObjectId("5f079d0369591c06b0fc981a"),
        "temperature" : 279,
        "recvTime" : ISODate("2020-07-09T22:41:05.670Z")
}
{
        "_id" : ObjectId("5f07a9eb69591c06b0fc981b"),
        "temperature" : 0.333,
        "recvTime" : ISODate("2020-07-09T23:36:11.160Z")
}

When I run: http://localhost:8666/STH/v1/contextEntities/type/Tank/id/Tank1/attributes/temperature?aggrMethod=sum&aggrPeriod=minute

or

http://localhost:8666/STH/v2/entities/Tank1/attrs/temperature?type=Tank&aggrMethod=sum&aggrPeriod=minute

I have the result: "sum": 279 and "sum": 0.333. I can recover ALL the aggregated data, max, min, sum, sum2.

The difficulty is with the STH-Comet when I try to retrieve the raw data, the return code is 200 and the value returns empty.

I've tried with APIs v1 and v2, to no avail.

request with v2:

http://sth:8666/STH/v2/entities/Tank1/attrs/temperature?type=Tank&lastN=10

Return

{
  "type": "StructuredValue",
  "value": []
}

request with v1:

http://sth:8666/STH/v1/contextEntities/type/Tank/id/Tank1/attributes/temperature?lastN=10

Return

{
  "contextResponses": [{
    "contextElement": {
      "attributes": [{
        "name": "temperature",
        "values": []
      }],
      "id": "Tank1",
      "isPattern": false,
      "type": "Tank"
    },
    "statusCode": {
      "code": "200",
      "reasonPhrase": "OK"
    }
  }]
}

The STH-Comet log shows that it is online and connects to the correct database:

time=2020-07-09T22:39:06.698Z | lvl=INFO | corr=n/a | trans=n/a | op=OPER_STH_DB_CONN_OPEN | from=n/a | srv=n/a | subsrv=n/a | comp=STH | msg=Establishing connection to the database at mongodb://@mongo:27017/sth_tese
time=2020-07-09T22:39:06.879Z | lvl=INFO | corr=n/a | trans=n/a | op=OPER_STH_DB_CONN_OPEN | from=n/a | srv=n/a | subsrv=n/a | comp=STH | msg=Connection successfully established to the database at mongodb://@mongo:27017/sth_tese
time=2020-07-09T22:39:07.218Z | lvl=INFO | corr=n/a | trans=n/a | op=OPER_STH_SERVER_START | from=n/a | srv=n/a | subsrv=n/a | comp=STH | msg=Server started at http://0.0.0.0:8666

The STH-Comet log with the api v2 request:

time=2020-07-09T23:46:47.400Z | lvl=DEBUG | corr=998811d9-fac2-4701-b37c-bb9ae1b45b81 | trans=998811d9-fac2-4701-b37c-bb9ae1b45b81 | op=OPER_STH_GET | from=n/a | srv=tese | subsrv=/iot | comp=STH | msg=GET /STH/v2/entities/Tank1/attrs/temperature?type=Tank&lastN=10
time=2020-07-09T23:46:47.404Z | lvl=DEBUG | corr=998811d9-fac2-4701-b37c-bb9ae1b45b81 | trans=998811d9-fac2-4701-b37c-bb9ae1b45b81 | op=OPER_STH_GET | from=n/a | srv=tese | subsrv=/iot | comp=STH | msg=Getting access to the raw data collection for retrieval...
time=2020-07-09T23:46:47.408Z | lvl=DEBUG | corr=998811d9-fac2-4701-b37c-bb9ae1b45b81 | trans=998811d9-fac2-4701-b37c-bb9ae1b45b81 | op=OPER_STH_GET | from=n/a | srv=tese | subsrv=/iot | comp=STH | msg=The raw data collection for retrieval exists
time=2020-07-09T23:46:47.412Z | lvl=DEBUG | corr=998811d9-fac2-4701-b37c-bb9ae1b45b81 | trans=998811d9-fac2-4701-b37c-bb9ae1b45b81 | op=OPER_STH_GET | from=n/a | srv=tese | subsrv=/iot | comp=STH | msg=No raw data available for the request: /STH/v2/entities/Tank1/attrs/temperature?type=Tank&lastN=10
time=2020-07-09T23:46:47.412Z | lvl=DEBUG | corr=998811d9-fac2-4701-b37c-bb9ae1b45b81 | trans=998811d9-fac2-4701-b37c-bb9ae1b45b81 | op=OPER_STH_GET | from=n/a | srv=tese | subsrv=/iot | comp=STH | msg=Responding with no points

According to the log, it establishes the connection to recover the raw data: msg=Getting access to the raw data collection for retrieval.... Confirms that the raw data exists: msg=The raw data collection for retrieval exists. But, it cannot recover this data and generates the message that the raw data is not available and does not return any points:msg=No raw data available for the request and msg=Responding with no points.

I already read the configuration part in the documentation. I've reinstalled everything, several times. I combed all settings and I can't find anything to justify this problem.

What could it be? Could someone with expertise in STH-Comet give any guidance?

Thanks!

Upvotes: 1

Views: 281

Answers (1)

fgalan
fgalan

Reputation: 12294

Sometimes the way in which STH tries to recover information doesn't match to the way in wich Cygnus store it. However, that doesn't to be the case here. The datamodel used by STH is configured with config.database.dataModel and it seems to be correct: collection-per-entity (as you have collections like sth_/iot_Tank1_Tank, which correspondds to a single entity, i.e. the one with id Tank1 and type Tank).

Assuming that the setting in config.js is not being overridden by DATA_MODEL env var (although it would be wise to check that, looking to the env vars actuallly inyected to the docker container running STH, I guess that with docker inspect) the only way I think we can continue debugging is to inspect which actual query does STH on MongoDB to end in No raw data available for the request.

MongoDB has a profiler that allows to record every query done in the DB. Thus the procedure would be as follows:

  1. Avoid (or minimize) any other usage of MongoDB instance, to avoid "noise" in the information recorded by the profiler
  2. Start the profiler in "all queries" mode (i.e. profiling level 2)
  3. Do the query at STH API
  4. Stop the profiler
  5. Check the queries recorded by the profiler as a consequence of the request done in step 3

Explaining the usage of the MongoDB profiler is out of the scope of this answer, but the reference I provided above is a good starting point if you don't know it already.

Once you have information about the queries, please provide feedback as comments to this answers. Thanks!

Upvotes: 0

Related Questions