Skip to content

Commit

Permalink
Update to newest version of weaver. (#119)
Browse files Browse the repository at this point in the history
The protocol between the envelope and the weavelet has changed recently.
This change updates weaver-gke to a new version of weaver and therefore
the new protocol.
  • Loading branch information
ghemawat authored Feb 14, 2024
1 parent 6627cde commit 212709a
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 329 deletions.
2 changes: 1 addition & 1 deletion examples/echo/weaver_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ package gen
//go:generate ./dev/protoc.sh internal/store/store.proto
//go:generate ./dev/protoc.sh internal/local/local.proto
//go:generate ./dev/protoc.sh internal/local/proxy/proxy.proto
//go:generate weaver generate ./internal/babysitter
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
cloud.google.com/go/monitoring v1.15.1
cloud.google.com/go/security v1.15.1
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.11.0
github.com/ServiceWeaver/weaver v0.22.1-0.20231019162801-c2294d1ae0e8
github.com/ServiceWeaver/weaver v0.22.1-0.20240208183719-2eb6066c2f85
github.com/golang/protobuf v1.5.3
github.com/google/cel-go v0.17.1
github.com/google/go-cmp v0.5.9
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapp
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.35.0/go.mod h1:H785fvlgotVZqht+1rHhXSs8EJ8uPVmpBYkTYO3ccpc=
github.com/ServiceWeaver/weaver v0.22.1-0.20231019162801-c2294d1ae0e8 h1:smtruzdiiELIMDNHrXD+fY8/I69p0rQPqMlYERptwA4=
github.com/ServiceWeaver/weaver v0.22.1-0.20231019162801-c2294d1ae0e8/go.mod h1:j27YowX7vVpIrYcEPZ9e1FR+fvVrlH9DweyO3uyOqkg=
github.com/ServiceWeaver/weaver v0.22.1-0.20240208183719-2eb6066c2f85 h1:nvYGb2V6IdwCSfDXpR4ruo1GD9919+2pnsPLcui0QbU=
github.com/ServiceWeaver/weaver v0.22.1-0.20240208183719-2eb6066c2f85/go.mod h1:j27YowX7vVpIrYcEPZ9e1FR+fvVrlH9DweyO3uyOqkg=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down
62 changes: 17 additions & 45 deletions internal/babysitter/babysitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import (
"crypto/x509"
"fmt"
"log/slog"
"net"
"net/http"
"path/filepath"
"sync"
"time"

Expand All @@ -30,7 +28,6 @@ import (
"github.com/ServiceWeaver/weaver-gke/internal/mtls"
"github.com/ServiceWeaver/weaver-gke/internal/nanny"
"github.com/ServiceWeaver/weaver/runtime"
"github.com/ServiceWeaver/weaver/runtime/deployers"
"github.com/ServiceWeaver/weaver/runtime/envelope"
"github.com/ServiceWeaver/weaver/runtime/logging"
"github.com/ServiceWeaver/weaver/runtime/metrics"
Expand Down Expand Up @@ -88,21 +85,6 @@ func Start(
traceSaver func(spans *protos.TraceSpans) error,
metricExporter func(metrics []*metrics.MetricSnapshot) error,
) (*Babysitter, error) {
// Custom logging component to receive log messages.
loggerComponent := &loggerImpl{dst: logSaver}

// Make Unix domain socket listener for serving hosted system components.
tmpDir, err := runtime.NewTempDir()
if err != nil {
return nil, err
}
// TODO(sanjay): Use runtime.OnExitSignal to cleanup when available.
udsPath := filepath.Join(tmpDir, "socket")
uds, err := net.Listen("unix", udsPath)
if err != nil {
return nil, err
}

// Create the envelope.
//
// We use the PodName as a unique weavelet id for the following reasons:
Expand All @@ -112,24 +94,18 @@ func Start(
// * It allows the manager to quickly check if the weavelet is still
// active by asking the Kubernetes API if the Pod with a given name
// exists.
info := &protos.EnvelopeInfo{
args := &protos.WeaveletArgs{
App: cfg.Deployment.App.Name,
DeploymentId: cfg.Deployment.Id,
Id: podName,
Sections: cfg.Deployment.App.Sections,
RunMain: replicaSet == runtime.Main,
Mtls: cfg.Mtls,
InternalAddress: internalAddress,
Redirects: []*protos.EnvelopeInfo_Redirect{
// Override the builtin logger.
{
Component: weaverLoggerName,
Target: funcLoggerName,
Address: "unix://" + udsPath,
},
},
// ControlSocket, Redirects filled by envelope.NewEnvelope
}
e, err := envelope.NewEnvelope(ctx, info, cfg.Deployment.App)
e, err := envelope.NewEnvelope(ctx, args, cfg.Deployment.App, envelope.Options{
Logger: logger,
})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -168,24 +144,12 @@ func Start(
// Watch for components to start.
go b.watchComponentsToStart()

// Serve calls to system components.
go func() {
sys := map[string]any{
funcLoggerName: loggerComponent,
}
if err := deployers.ServeComponents(ctx, uds, logger, sys); err != nil {
panic(err)
}
}()

return b, nil
}

// WeaveletInfo returns information about the weavelet managed by the
// babysitter.
func (b *Babysitter) WeaveletInfo() *protos.WeaveletInfo {
return b.envelope.WeaveletInfo()
}
// WeaveletAddress returns the address that other components should dial to communicate with the
// weavelet.
func (b *Babysitter) WeaveletAddress() string { return b.envelope.WeaveletAddress() }

// SelfAddr returns the address on which the babysitter is listening on
// for incoming requests.
Expand Down Expand Up @@ -231,7 +195,7 @@ func (b *Babysitter) GetLoad(_ context.Context, req *endpoints.GetLoadRequest) (
}
return &endpoints.GetLoadReply{
Load: load,
WeaveletAddr: b.WeaveletInfo().DialAddr,
WeaveletAddr: b.WeaveletAddress(),
}, nil
}

Expand All @@ -245,6 +209,14 @@ func (b *Babysitter) RunProfiling(_ context.Context, req *protos.GetProfileReque
return &protos.GetProfileReply{Data: prof}, nil
}

// LogBatch implements the control.DeployerControl interface.
func (b *Babysitter) LogBatch(ctx context.Context, batch *protos.LogEntryBatch) error {
for _, entry := range batch.Entries {
b.logSaver(entry)
}
return nil
}

// ActivateComponent implements the envelope.EnvelopeHandler interface.
func (b *Babysitter) ActivateComponent(ctx context.Context, req *protos.ActivateComponentRequest) (*protos.ActivateComponentReply, error) {
targetReplicaSet := config.ReplicaSetForComponent(req.Component, b.cfg)
Expand Down
45 changes: 0 additions & 45 deletions internal/babysitter/logger.go

This file was deleted.

Loading

0 comments on commit 212709a

Please sign in to comment.