-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add streaming updates core functionality and project streaming (#…
…8669) --------- Co-authored-by: Ryan <rb@hpe.com> & Eric L. <eric.liu@hpe.com>
- Loading branch information
1 parent
ed61121
commit 6206bde
Showing
24 changed files
with
2,822 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package stream | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/lib/pq" | ||
|
||
"github.com/determined-ai/determined/master/pkg/model" | ||
) | ||
|
||
// StreamAuthZBasic is classic OSS Determined authentication for streaming clients. | ||
type StreamAuthZBasic struct{} | ||
|
||
// GetProjectStreamableScopes always returns an AccessScopeSet with global permissions and a nil error. | ||
func (a *StreamAuthZBasic) GetProjectStreamableScopes( | ||
_ context.Context, | ||
_ model.User, | ||
) (model.AccessScopeSet, error) { | ||
return model.AccessScopeSet{model.GlobalAccessScopeID: true}, nil | ||
} | ||
|
||
// GetPermissionChangeListener always returns a nil pointer and a nil error. | ||
func (a *StreamAuthZBasic) GetPermissionChangeListener() (*pq.Listener, error) { | ||
return nil, nil | ||
} | ||
|
||
func init() { | ||
AuthZProvider.Register("basic", &StreamAuthZBasic{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package stream | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/lib/pq" | ||
|
||
"github.com/determined-ai/determined/master/internal/authz" | ||
"github.com/determined-ai/determined/master/pkg/model" | ||
) | ||
|
||
// StreamAuthZ is the interface for streaming authorization. | ||
type StreamAuthZ interface { | ||
// GetProjectStreamableScopes returns an AccessScopeSet where the user has permission to view projects. | ||
GetProjectStreamableScopes(ctx context.Context, curUser model.User) (model.AccessScopeSet, error) | ||
|
||
// GetPermissionChangeListener returns a pointer listener | ||
// listening for permission change notifications if applicable. | ||
GetPermissionChangeListener() (*pq.Listener, error) | ||
} | ||
|
||
// AuthZProvider provides StreamAuthZ implementations. | ||
var AuthZProvider authz.AuthZProviderType[StreamAuthZ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package stream | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/gorilla/websocket" | ||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/determined-ai/determined/master/pkg/stream" | ||
) | ||
|
||
// StartupMsg is the first message a streaming client sends. | ||
// | ||
// It declares initially known keys and also configures the initial subscriptions for the stream. | ||
type StartupMsg struct { | ||
SyncID string `json:"sync_id"` | ||
Known KnownKeySet `json:"known"` | ||
Subscribe SubscriptionSpecSet `json:"subscribe"` | ||
} | ||
|
||
// KnownKeySet allows a client to describe which primary keys it knows of as existing, | ||
// so the server can respond with which client-known keys have been deleted or disappeared, | ||
// and also which server-known keys are not yet known to the client (appearances). | ||
// | ||
// Each field of a KnownKeySet is a comma-separated list of int64s and ranges like "a,b-c,d". | ||
type KnownKeySet struct { | ||
Projects string `json:"projects"` | ||
} | ||
|
||
// prepareWebsocketMessage converts the MarshallableMsg into a websocket.PreparedMessage. | ||
func prepareWebsocketMessage(obj stream.MarshallableMsg) interface{} { | ||
jbytes, err := json.Marshal(obj) | ||
if err != nil { | ||
log.Errorf("error marshaling message for streaming: %s", err.Error()) | ||
return nil | ||
} | ||
msg, err := websocket.NewPreparedMessage(websocket.TextMessage, jbytes) | ||
if err != nil { | ||
log.Errorf("error preparing message for streaming: %s", err.Error()) | ||
return nil | ||
} | ||
return msg | ||
} |
Oops, something went wrong.