Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useview_telemetry is failing for instances running on CHT-Core > 3.8.0 #87

Closed
dianabarsan opened this issue May 17, 2021 · 3 comments
Closed
Assignees
Labels

Comments

@dianabarsan
Copy link
Member

Reported error:

[2021-05-17T08:32:50.708Z ERROR]:  { error: date/time field value out of range: "2020-13-1"
    at Connection.parseE (/var/adapter/shared/medic-couch2pg-v3.2.1/node_modules/pg/lib/connection.js:545:11)
    at Connection.parseMessage (/var/adapter/shared/medic-couch2pg-v3.2.1/node_modules/pg/lib/connection.js:370:19)
    at Socket.<anonymous> (/var/adapter/shared/medic-couch2pg-v3.2.1/node_modules/pg/lib/connection.js:113:22)
    at emitOne (events.js:125:13)
    at Socket.emit (events.js:221:7)
    at addChunk (_stream_readable.js:265:12)
    at readableAddChunk (_stream_readable.js:252:11)
    at Socket.Readable.push (_stream_readable.js:209:10)
    at TCP.onread (net.js:598:20)
  name: 'error',
  length: 294,
  severity: 'ERROR',
  code: '22008',
  detail: undefined,
  hint: 'Perhaps you need a different "datestyle" setting.',
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: 'SQL statement "REFRESH MATERIALIZED VIEW CONCURRENTLY useview_telemetry"\nPL/pgSQL function refresh_matviews() line 15 at EXECUTE',
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'datetime.c',
  line: '3890',
  routine: 'DateTimeParseError' }

It seems like this is related to this migration:
https://github.com/medic/medic-couch2pg/blob/master/libs/medic-users-meta/migrations/202102191153.do.54-create-couchdb-users-meta-table.sql#L27

Where, instead of adding +1 when the instance version is lower than 3.8.0, we end up adding +1 when the instance is equal or greater, ending up with 13th month dates.

@mrsarm mrsarm self-assigned this May 17, 2021
@mrsarm
Copy link
Contributor

mrsarm commented May 17, 2021

Assigning myself because I'll work today in the solution for #86 that affects the same view, and doing separate PRs from each one would imply 2 different migrations scripts, recreating 2 times the same view, because PG does not allow to alter views to just change column definitions.

@mrsarm
Copy link
Contributor

mrsarm commented May 19, 2021

Ready for AT, along with the issues #85 and #86, branch 86-87-fix-meta-views.

The description of the changes are described in the PR description: #91

More on what to test: #86 (comment)

@newtewt
Copy link

newtewt commented May 21, 2021

confirmed that versions 3.11.0 and 3.7.0 creating telemetry and thing syncing to postgress are not failing and have the proper month set.

mrsarm added a commit that referenced this issue May 21, 2021
…ily telemetry (#91)

Deprecate old `medic-users-meta` views and create new ones fixing bugs and making compatible with upcoming daily telemetry.

**Issues**: #85 , #86 , #87

**Changes**:

- [Bug] Change the indexes for both views (telemetry and feedback) based on the columns user_name and period_start, the PR remove the unique constraint to avoid collisions, and instead the uuid of the records are used as unique index to allow concurrent refresh of the views (#86).
- [Bug] Fix bug that causes records being parsed with months 0-indexed as 1-indexed and vice versa (thanks to @kitsao ) (#87).
- [Improvement] The column period_start from the telemetry view has the same DATE type, but the day component is parsed from the JSON metadata.day field if present (daily aggregation telemetry from this upcoming CHT feature), otherwise defaulted to 1 as it was before to maintain backward compatibility with monthly aggregation telemetry (#85).

**Affected views**:

- Feedback view: `useview_feedback`
- Telemetry view: `useview_telemetry`
@mrsarm mrsarm closed this as completed May 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants