-
Notifications
You must be signed in to change notification settings - Fork 111
/
runtime.go
86 lines (76 loc) · 2.53 KB
/
runtime.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package runtime
import (
"context"
"errors"
"fmt"
"math"
"time"
runtimev1 "github.com/rilldata/rill/proto/gen/rill/runtime/v1"
"github.com/rilldata/rill/runtime/drivers"
"github.com/rilldata/rill/runtime/pkg/activity"
"go.uber.org/zap"
)
type Options struct {
ConnectionCacheSize int
MetastoreConnector string
QueryCacheSizeBytes int64
SecurityEngineCacheSize int
AllowHostAccess bool
SafeSourceRefresh bool
// SystemConnectors are drivers whose handles are shared with all instances
SystemConnectors []*runtimev1.Connector
}
type Runtime struct {
opts *Options
metastore drivers.Handle
logger *zap.Logger
connCache *connectionCache
migrationMetaCache *migrationMetaCache
queryCache *queryCache
securityEngine *securityEngine
activity activity.Client
}
func New(opts *Options, logger *zap.Logger, client activity.Client) (*Runtime, error) {
rt := &Runtime{
opts: opts,
logger: logger,
migrationMetaCache: newMigrationMetaCache(math.MaxInt),
queryCache: newQueryCache(opts.QueryCacheSizeBytes),
securityEngine: newSecurityEngine(opts.SecurityEngineCacheSize, logger),
activity: client,
}
rt.connCache = newConnectionCache(opts.ConnectionCacheSize, logger, rt, client)
store, _, err := rt.AcquireSystemHandle(context.Background(), opts.MetastoreConnector)
if err != nil {
return nil, err
}
// Check the metastore is a registry
_, ok := store.AsRegistry()
if !ok {
return nil, fmt.Errorf("server metastore must be a valid registry")
}
rt.metastore = store
return rt, nil
}
func (r *Runtime) AllowHostAccess() bool {
return r.opts.AllowHostAccess
}
func (r *Runtime) Close() error {
return errors.Join(
r.metastore.Close(),
r.connCache.Close(),
r.queryCache.close(),
)
}
func (r *Runtime) Controller(instanceID string) (*Controller, error) {
panic("not implemented")
}
func (r *Runtime) ResolveMetricsViewSecurity(attributes map[string]any, instanceID string, mv *runtimev1.MetricsView, lastUpdatedOn time.Time) (*ResolvedMetricsViewSecurity, error) {
return r.securityEngine.resolveMetricsViewSecurity(attributes, instanceID, mv, lastUpdatedOn)
}
func (r *Runtime) ResolveMetricsViewSecurityV2(attributes map[string]any, instanceID string, mv *runtimev1.MetricsViewSpec, lastUpdatedOn time.Time) (*ResolvedMetricsViewSecurity, error) {
// TODO: Implement actual checks when deprecating ResolveMetricsViewSecurity
return &ResolvedMetricsViewSecurity{
Access: true,
}, nil
}