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

storagenode/notifications: db created #3707

Merged
merged 18 commits into from
Dec 16, 2019

Conversation

VitaliiShpital
Copy link
Member

@VitaliiShpital VitaliiShpital commented Dec 6, 2019

What:
db for notification system for SN implemented

Why:
SN Notification System MVP

Please describe the tests:

  • Test 1:
  • Test 2:

Please describe the performance impact:

Code Review Checklist (to be filled out by reviewer)

  • NEW: Are there any Satellite database migrations? Are they forwards and backwards compatible?
  • Does the PR describe what changes are being made?
  • Does the PR describe why the changes are being made?
  • Does the code follow our style guide?
  • Does the code follow our testing guide?
  • Is the PR appropriately sized? (If it could be broken into smaller PRs it should be)
  • Does the new code have enough tests? (every PR should have tests or justification otherwise. Bug-fix PRs especially)
  • Does the new code have enough documentation that answers "how do I use it?" and "what does it do?"? (both source documentation and higher level, diagrams?)
  • Does any documentation need updating?
  • Do the database access patterns make sense?

@VitaliiShpital VitaliiShpital added the Request Code Review Code review requested label Dec 6, 2019
@cla-bot cla-bot bot added the cla-signed label Dec 6, 2019
@ghost ghost removed their request for review December 6, 2019 15:56
"storj.io/storj/pkg/storj"
)

// DB is an implementation of notifications.Notifications.
Copy link
Contributor

Choose a reason for hiding this comment

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

it's interface, not implementation
this DB interface exposes the way how to manage records in your db implementation


// Notification holds notification entity info which is being retrieved from database.
type Notification struct {
ID uuid.UUID
Copy link
Contributor

Choose a reason for hiding this comment

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

should we inherit Notification from the NewNotification?

Copy link
Member Author

Choose a reason for hiding this comment

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

let's leave it as it is for better readability

"testing"
"time"

"storj.io/storj/private/testrand"
Copy link
Contributor

Choose a reason for hiding this comment

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

reorder imports

Page: 1,
}

// test read.
Copy link
Contributor

Choose a reason for hiding this comment

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

this comments are not meaningful


page := notifications.NotificationPage{}

// test paged list.
Copy link
Contributor

Choose a reason for hiding this comment

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

this comment is not meaningful

assert.Equal(t, page.Notifications[2].ReadAt, (*time.Time)(nil))
})

// test read all.
Copy link
Contributor

Choose a reason for hiding this comment

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

this comment is not meaningful

}

// Insert puts new notification to database.
func (repo *notificationDB) Insert(ctx context.Context, notification notifications.NewNotification) (_ notifications.Notification, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

repo is a bad name for this receiver. Lets name it db?

)

// bytesToUUID is used to convert []byte to UUID
func bytesToUUID(data []byte) (uuid.UUID, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this method is used in satellitedb and in storagenodedb. What if we place it in pkg or private?

Copy link
Member Author

Choose a reason for hiding this comment

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

let me do it in another PR since it's not in scope of this one

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this should be done within the PR, else its forgotten about.
Especially if reusing existing code, moving it into another package is fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

if i do it within this PR it's size would become really big, cause i'll have to update a lot of repositories in satellite and storagenode. I'll create a ticket in Jira not to forget about it

NotificationTypeDisqualification NotificationType = 3
)

// NewNotification holds notification entity info which is being inserted to database.
Copy link
Contributor

Choose a reason for hiding this comment

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

which is being received from satellite

"storj.io/storj/pkg/storj"
)

// DB works with notifications database.
Copy link
Contributor

Choose a reason for hiding this comment

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

DB tells us how application want to work with db

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.

package notifications
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets avoid a second package name with similar name in regards to PR #3659

Copy link
Contributor

Choose a reason for hiding this comment

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

why do we care? it is the same as satellite/orders and storagenode/orders or console pkg


const (
// NotificationTypeCustom is a common notification type which doesn't describe node's core functionality.
NotificationTypeCustom NotificationType = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this Type will be misused in the future.
We should make something along the lines of Information..

Copy link
Member Author

Choose a reason for hiding this comment

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

now we don't know all custom notification types. Let's wait for all the info about it. I'll add TODO for this. Are you ok with that?

Copy link
Contributor

Choose a reason for hiding this comment

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

custom notification can have any topic, for example it can be notification about new blogpost, New Year sale, payouts made etc.

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.

package notifications_test
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

)

// bytesToUUID is used to convert []byte to UUID
func bytesToUUID(data []byte) (uuid.UUID, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this should be done within the PR, else its forgotten about.
Especially if reusing existing code, moving it into another package is fine.

storagenode/storagenodedb/notifications.go Outdated Show resolved Hide resolved
storagenode/storagenodedb/notifications.go Outdated Show resolved Hide resolved
storagenode/storagenodedb/notifications.go Outdated Show resolved Hide resolved
storagenode/storagenodedb/notifications.go Outdated Show resolved Hide resolved
storagenode/storagenodedb/notifications.go Show resolved Hide resolved
storagenode/storagenodedb/notifications.go Outdated Show resolved Hide resolved
storagenode/storagenodedb/notifications.go Outdated Show resolved Hide resolved
storagenode/nodenotifications/notifications.go Outdated Show resolved Hide resolved
Copy link
Contributor

@stefanbenten stefanbenten left a comment

Choose a reason for hiding this comment

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

The package name still isnt matching the one of #3659 , which it definitely should.
Thank you so much for making the UUID conversion changes in this PR!

storagenode/nodenotifications/notifications.go Outdated Show resolved Hide resolved
stefanbenten
stefanbenten previously approved these changes Dec 10, 2019
Copy link
Contributor

@stefanbenten stefanbenten left a comment

Choose a reason for hiding this comment

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

Besides the comments from @rikysya and ensuring the package names match with #3659 this looks good to go!

@VitaliiShpital VitaliiShpital added the Reviewer Can Merge If all checks have passed, non-owner can merge PR label Dec 10, 2019
@rikysya rikysya changed the title storagenode: notifications db created storagenode/notifications: db created Dec 16, 2019
@VitaliiShpital VitaliiShpital merged commit 53d9bc4 into master Dec 16, 2019
@VitaliiShpital VitaliiShpital deleted the vs/storagenode_notifications_db_creating branch December 16, 2019 17:59
}

// NotificationType is a numeric value of specific notification type.
type NotificationType int
Copy link
Member

Choose a reason for hiding this comment

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

Stutter. notifications.NotificationType, notifcations.Type would be sufficent. See

const (
// NotificationTypeCustom is a common notification type which doesn't describe node's core functionality.
// TODO: change type name when all notification types will be known
NotificationTypeCustom NotificationType = 0
Copy link
Member

Choose a reason for hiding this comment

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

Stutter and long notifications.NotificationTypeCustom (same for others)

}

// NotificationCursor holds notification cursor entity which is used to create listed page from database.
type NotificationCursor struct {
Copy link
Member

Choose a reason for hiding this comment

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

stutter notifications.NotificationCursor

}

// NotificationPage holds notification page entity which is used to show listed page of notifications on UI.
type NotificationPage struct {
Copy link
Member

Choose a reason for hiding this comment

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

stutter notifications.NotificationPage

}

// NotificationType is a numeric value of specific notification type.
type NotificationType int
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason this isn't a string constant instead of an number?

// NewNotification holds notification entity info which is being received from satellite or local client.
type NewNotification struct {
SenderID storj.NodeID
Type NotificationType
Copy link
Member

Choose a reason for hiding this comment

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

Can notifications have only one type? Maybe it should be tags?

Copy link
Contributor

Choose a reason for hiding this comment

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

what do you mean? could you please provide an example?

Copy link
Member

Choose a reason for hiding this comment

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

For example, could the notification be a warning and audit, or something similar? Currently it seems we end up with tons of constants that all try to encode different ideas into a single enumeration. Usually, the level and scope are separated. For some logging/notification systems there's support for custom tags.

Copy link
Contributor

@rikysya rikysya Dec 16, 2019

Choose a reason for hiding this comment

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

hm, yeah. So you think we should add fields for level and for tags? And probably rename type to scope?

Copy link
Member

@egonelbre egonelbre Dec 17, 2019

Choose a reason for hiding this comment

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

It's more of a question, . I.e. I don't have a strong argument either way, but I usually just have seen them separated, mainly because it's more flexible (and avoid proliferation of constants). Strings also end up being forwards compatible.

bryanchriswhite added a commit that referenced this pull request Dec 17, 2019
* storj/master: (27 commits)
  storagenode/garbagecollection: enable in production
  satellite: adds and enables cockroachdb compatibility for tests
  scripts: Add script that filters postgres plaintext backup to cockroachdb compat.
  Adding benchmarking script that reports response times.
  pkg/rpc: Change drpcheader to save a packet
  private/dbutil: register "cockroach" as sql.DB driver
  satellite/satellitedb: unexport satellitedb.DB
  ci: remove Jenkinsfile.drpc
  web/satellite: billing banner changed
  satellitedb: fix migration cockroach test
  storagenode/notifications: db created (#3707)
  web/satellite: project limits
  do not update pointer for failed audits
  uplink/storage: remove unused Meta methods
  storagenode/orderdb: fix db lock
  storagenode/trust: wire up list into pool
  cmd/segment-reaper: Add test cases from/to processSegment
  lib/uplinkc: use SliceHeader instead of [1<<30]
  satellite/metainfo: Improve docs & use common funcs
  Use Postgres 9.6 for Jenkins builds (#3729)
  ...

Change-Id: I437a8960a3b0b203a2e82bec5e4badaeb8f11563
VinozzZ pushed a commit that referenced this pull request Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed Request Code Review Code review requested Reviewer Can Merge If all checks have passed, non-owner can merge PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants