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

MG-94 - Add storage for dashboards #104

Merged
merged 17 commits into from
Feb 5, 2024

Conversation

felixgateru
Copy link
Contributor

What type of PR is this?

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update
  • Dependency Update

What does this do?

Adds postgress implementation for storage of dashboards

Which issue(s) does this PR fix/relate to?

Have you included tests for your changes?

  • Yes
  • No, and this is why: will do so

Did you document any new/modified functionality?

  • Yes
  • No, and this is why:

Notes

@felixgateru felixgateru changed the base branch from main to dashboards January 30, 2024 18:07
@dborovcanin dborovcanin added the dashboards Dashboards label Jan 31, 2024
@felixgateru felixgateru force-pushed the NOISSUE_storage branch 6 times, most recently from 27993e3 to 230edae Compare February 1, 2024 08:29
@felixgateru felixgateru force-pushed the NOISSUE_storage branch 2 times, most recently from 2db28a2 to 9e93b0d Compare February 1, 2024 13:08
@felixgateru felixgateru marked this pull request as ready for review February 1, 2024 13:10
ui/service.go Show resolved Hide resolved
ui/web/static/js/dashboards.js Outdated Show resolved Hide resolved
ui/web/templates/dashboard.html Outdated Show resolved Hide resolved
ui/dashboards.go Outdated Show resolved Hide resolved
ui/api/logging.go Outdated Show resolved Hide resolved
ui/api/logging.go Outdated Show resolved Hide resolved
lm.logger.Warn("View dashboards failed to complete successfully", args...)
return
}
lm.logger.Info("View dashboards completed successfully", args...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lm.logger.Info("View dashboards completed successfully", args...)
lm.logger.Info("View dashboard completed successfully", args...)

ui/api/logging.go Outdated Show resolved Hide resolved
ui/api/metrics.go Outdated Show resolved Hide resolved
ui/api/metrics.go Outdated Show resolved Hide resolved
ui/service.go Outdated Show resolved Hide resolved
ui/service.go Outdated Show resolved Hide resolved
ui/service.go Outdated Show resolved Hide resolved
ui/service.go Outdated Show resolved Hide resolved
postgres/dashboards.go Outdated Show resolved Hide resolved
ui/service.go Outdated Show resolved Hide resolved
ui/api/metrics.go Outdated Show resolved Hide resolved
ui/api/logging.go Outdated Show resolved Hide resolved
Signed-off-by: felix.gateru <[email protected]>
Signed-off-by: felix.gateru <[email protected]>
Signed-off-by: felix.gateru <[email protected]>
docker/docker-compose.yml Outdated Show resolved Hide resolved
docker/.env Outdated Show resolved Hide resolved
internal/postgres/postgres.go Outdated Show resolved Hide resolved
internal/env/parser.go Outdated Show resolved Hide resolved
postgres/dashboards.go Outdated Show resolved Hide resolved
ui/api/logging.go Outdated Show resolved Hide resolved
ui/api/logging.go Outdated Show resolved Hide resolved
ui/api/logging.go Outdated Show resolved Hide resolved
ui/api/logging.go Outdated Show resolved Hide resolved
ui/api/logging.go Outdated Show resolved Hide resolved
ui/service.go Outdated Show resolved Hide resolved
ui/dashboards.go Outdated Show resolved Hide resolved
docker/.env Outdated Show resolved Hide resolved
docker/docker-compose.yml Outdated Show resolved Hide resolved
docker/docker-compose.yml Outdated Show resolved Hide resolved
docker/docker-compose.yml Outdated Show resolved Hide resolved
docker/docker-compose.yml Outdated Show resolved Hide resolved
docker/docker-compose.yml Outdated Show resolved Hide resolved
Signed-off-by: felix.gateru <[email protected]>
ui/service.go Outdated
return btpl.Bytes(), errors.Wrap(ErrFailedRetrieveUserID, err)
}

entropy := rand.New(rand.NewSource(time.Now().UnixNano()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for uniformity of the id's I suggest you use the Magistrala format for uuid: https://github.com/absmach/magistrala/blob/main/pkg/uuid/uuid.go


// Retrieve all dashboards for a user using a user id.
func (r *repo) RetrieveAll(ctx context.Context, page ui.DashboardPageMeta) (ui.DashboardPage, error) {
q := `SELECT dashboard_id, created_by, dashboard_name, description, metadata, created_at, updated_at FROM dashboards WHERE created_by = :created_by LIMIT :limit OFFSET :offset`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ORDER BY created_at to retrieve beginning with the latest dashboard

restart: on-failure
command: postgres -c "max_connections=${MG_POSTGRES_MAX_CONNECTIONS}"
ports:
- 6044:5432
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 6044:5432
- 6042:5432

q := `
INSERT INTO dashboards (dashboard_id, created_by, dashboard_name, description, metadata, layout, created_at, updated_at)
VALUES (:dashboard_id, :created_by, :dashboard_name, :description, :metadata, :layout, :created_at, :updated_at)
RETURNING dashboard_id, created_by, dashboard_name, description, metadata, layout, created_at, updated_at`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RETURNING dashboard_id, created_by, dashboard_name, description, metadata, layout, created_at, updated_at`
RETURNING dashboard_id, created_by, dashboard_name, description, metadata, layout, created_at

Signed-off-by: felix.gateru <[email protected]>
Signed-off-by: felix.gateru <[email protected]>
postgres/init.go Outdated
Comment on lines 19 to 22
dashboard_id VARCHAR(36) NOT NULL,
created_by VARCHAR(36) NOT NULL,
dashboard_name VARCHAR(255) NOT NULL,
description TEXT,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a dashboard prefix for ID and name.

}

return uiRes{
code: http.StatusOK,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we do not return anything else, the correct code would be No Content. Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE.

postgres/init.go Outdated
created_by VARCHAR(36) NOT NULL,
dashboard_name VARCHAR(255) NOT NULL,
description TEXT,
metadata TEXT,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other entities it is added as the option for extension, but we probably do not need metadata for dashboards. Please remove.

Signed-off-by: felix.gateru <[email protected]>
@dborovcanin dborovcanin merged commit 0610abe into absmach:dashboards Feb 5, 2024
dborovcanin pushed a commit that referenced this pull request Feb 5, 2024
* Add postgres storage to dashboards

Signed-off-by: felix.gateru <[email protected]>

* Implement CRUD operations for dashboards

Signed-off-by: felix.gateru <[email protected]>

* Add Dashboard Name as a database field

Signed-off-by: felix.gateru <[email protected]>

* Fix db bug

Signed-off-by: felix.gateru <[email protected]>

* Fix retreive all error

Signed-off-by: felix.gateru <[email protected]>

* Refactor list dashboars response

Signed-off-by: felix.gateru <[email protected]>

* Revert port configuration to default

Signed-off-by: felix.gateru <[email protected]>

* Fix list dashboards bug

Signed-off-by: felix.gateru <[email protected]>

* Enhance update request

Signed-off-by: felix.gateru <[email protected]>

* Add standalone config

Signed-off-by: felix.gateru <[email protected]>

* Add created and updated time stamps

Signed-off-by: felix.gateru <[email protected]>

* Refactor dashboards.go

Signed-off-by: felix.gateru <[email protected]>

* Change dashboard id from ulid to uuid

Signed-off-by: felix.gateru <[email protected]>

* Change config urls

Signed-off-by: felix.gateru <[email protected]>

* cleaning up

Signed-off-by: felix.gateru <[email protected]>

* Revert config urls

Signed-off-by: felix.gateru <[email protected]>

* Rename dashboard id and name

Signed-off-by: felix.gateru <[email protected]>

---------

Signed-off-by: felix.gateru <[email protected]>
dborovcanin pushed a commit that referenced this pull request Feb 5, 2024
* Add postgres storage to dashboards

Signed-off-by: felix.gateru <[email protected]>

* Implement CRUD operations for dashboards

Signed-off-by: felix.gateru <[email protected]>

* Add Dashboard Name as a database field

Signed-off-by: felix.gateru <[email protected]>

* Fix db bug

Signed-off-by: felix.gateru <[email protected]>

* Fix retreive all error

Signed-off-by: felix.gateru <[email protected]>

* Refactor list dashboars response

Signed-off-by: felix.gateru <[email protected]>

* Revert port configuration to default

Signed-off-by: felix.gateru <[email protected]>

* Fix list dashboards bug

Signed-off-by: felix.gateru <[email protected]>

* Enhance update request

Signed-off-by: felix.gateru <[email protected]>

* Add standalone config

Signed-off-by: felix.gateru <[email protected]>

* Add created and updated time stamps

Signed-off-by: felix.gateru <[email protected]>

* Refactor dashboards.go

Signed-off-by: felix.gateru <[email protected]>

* Change dashboard id from ulid to uuid

Signed-off-by: felix.gateru <[email protected]>

* Change config urls

Signed-off-by: felix.gateru <[email protected]>

* cleaning up

Signed-off-by: felix.gateru <[email protected]>

* Revert config urls

Signed-off-by: felix.gateru <[email protected]>

* Rename dashboard id and name

Signed-off-by: felix.gateru <[email protected]>

---------

Signed-off-by: felix.gateru <[email protected]>
dborovcanin pushed a commit that referenced this pull request Feb 9, 2024
* Add postgres storage to dashboards

Signed-off-by: felix.gateru <[email protected]>

* Implement CRUD operations for dashboards

Signed-off-by: felix.gateru <[email protected]>

* Add Dashboard Name as a database field

Signed-off-by: felix.gateru <[email protected]>

* Fix db bug

Signed-off-by: felix.gateru <[email protected]>

* Fix retreive all error

Signed-off-by: felix.gateru <[email protected]>

* Refactor list dashboars response

Signed-off-by: felix.gateru <[email protected]>

* Revert port configuration to default

Signed-off-by: felix.gateru <[email protected]>

* Fix list dashboards bug

Signed-off-by: felix.gateru <[email protected]>

* Enhance update request

Signed-off-by: felix.gateru <[email protected]>

* Add standalone config

Signed-off-by: felix.gateru <[email protected]>

* Add created and updated time stamps

Signed-off-by: felix.gateru <[email protected]>

* Refactor dashboards.go

Signed-off-by: felix.gateru <[email protected]>

* Change dashboard id from ulid to uuid

Signed-off-by: felix.gateru <[email protected]>

* Change config urls

Signed-off-by: felix.gateru <[email protected]>

* cleaning up

Signed-off-by: felix.gateru <[email protected]>

* Revert config urls

Signed-off-by: felix.gateru <[email protected]>

* Rename dashboard id and name

Signed-off-by: felix.gateru <[email protected]>

---------

Signed-off-by: felix.gateru <[email protected]>
dborovcanin pushed a commit that referenced this pull request Feb 9, 2024
* Add postgres storage to dashboards

Signed-off-by: felix.gateru <[email protected]>

* Implement CRUD operations for dashboards

Signed-off-by: felix.gateru <[email protected]>

* Add Dashboard Name as a database field

Signed-off-by: felix.gateru <[email protected]>

* Fix db bug

Signed-off-by: felix.gateru <[email protected]>

* Fix retreive all error

Signed-off-by: felix.gateru <[email protected]>

* Refactor list dashboars response

Signed-off-by: felix.gateru <[email protected]>

* Revert port configuration to default

Signed-off-by: felix.gateru <[email protected]>

* Fix list dashboards bug

Signed-off-by: felix.gateru <[email protected]>

* Enhance update request

Signed-off-by: felix.gateru <[email protected]>

* Add standalone config

Signed-off-by: felix.gateru <[email protected]>

* Add created and updated time stamps

Signed-off-by: felix.gateru <[email protected]>

* Refactor dashboards.go

Signed-off-by: felix.gateru <[email protected]>

* Change dashboard id from ulid to uuid

Signed-off-by: felix.gateru <[email protected]>

* Change config urls

Signed-off-by: felix.gateru <[email protected]>

* cleaning up

Signed-off-by: felix.gateru <[email protected]>

* Revert config urls

Signed-off-by: felix.gateru <[email protected]>

* Rename dashboard id and name

Signed-off-by: felix.gateru <[email protected]>

---------

Signed-off-by: felix.gateru <[email protected]>
dborovcanin pushed a commit that referenced this pull request Feb 9, 2024
* Add postgres storage to dashboards

Signed-off-by: felix.gateru <[email protected]>

* Implement CRUD operations for dashboards

Signed-off-by: felix.gateru <[email protected]>

* Add Dashboard Name as a database field

Signed-off-by: felix.gateru <[email protected]>

* Fix db bug

Signed-off-by: felix.gateru <[email protected]>

* Fix retreive all error

Signed-off-by: felix.gateru <[email protected]>

* Refactor list dashboars response

Signed-off-by: felix.gateru <[email protected]>

* Revert port configuration to default

Signed-off-by: felix.gateru <[email protected]>

* Fix list dashboards bug

Signed-off-by: felix.gateru <[email protected]>

* Enhance update request

Signed-off-by: felix.gateru <[email protected]>

* Add standalone config

Signed-off-by: felix.gateru <[email protected]>

* Add created and updated time stamps

Signed-off-by: felix.gateru <[email protected]>

* Refactor dashboards.go

Signed-off-by: felix.gateru <[email protected]>

* Change dashboard id from ulid to uuid

Signed-off-by: felix.gateru <[email protected]>

* Change config urls

Signed-off-by: felix.gateru <[email protected]>

* cleaning up

Signed-off-by: felix.gateru <[email protected]>

* Revert config urls

Signed-off-by: felix.gateru <[email protected]>

* Rename dashboard id and name

Signed-off-by: felix.gateru <[email protected]>

---------

Signed-off-by: felix.gateru <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dashboards Dashboards
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add storage for dashboards
4 participants