Skip to content

feat(bladectl): add more bladectl commands #91

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

Merged
merged 3 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
253 changes: 190 additions & 63 deletions api/bladeapi/v1alpha1/blade.pb.go

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion api/bladeapi/v1alpha1/blade.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
syntax = "proto4";
syntax = "proto3";

import "google/protobuf/empty.proto";
package api.bladeapi.v1alpha1;
Expand Down Expand Up @@ -37,13 +37,22 @@ message EmitEventRequest {
Event event = 1;
}

message FanCurveStep {
int64 temperature = 1;
uint32 percent = 2;
}

message StatusResponse {
bool stealth_mode = 1;
bool identify_active = 2;
bool critical_active = 3;
int64 temperature = 4;
int64 fan_rpm = 5;
PowerStatus power_status = 6;
uint32 fan_percent = 7;
bool fan_speed_automatic = 8;
int64 critical_temperature_threshold = 9;
repeated FanCurveStep fan_curve_steps = 10;
}

service BladeAgentService {
Expand All @@ -53,9 +62,17 @@ service BladeAgentService {
// WaitForIdentifyConfirm blocks until the blades button is pressed
rpc WaitForIdentifyConfirm(google.protobuf.Empty) returns (google.protobuf.Empty) {}

// Sets the fan speed to a specific value.
rpc SetFanSpeed(SetFanSpeedRequest) returns (google.protobuf.Empty) {}

// Sets the fan speed to automatic mode.
//
// Internally, this is equivalent to calling SetFanSpeed with a nil/empty value.
rpc SetFanSpeedAuto(google.protobuf.Empty) returns (google.protobuf.Empty) {}

// Sets the blade to stealth mode (disables all LEDs)
rpc SetStealthMode(StealthModeRequest) returns (google.protobuf.Empty) {}

// Gets the current status of the blade
rpc GetStatus(google.protobuf.Empty) returns (StatusResponse) {}
}
49 changes: 49 additions & 0 deletions api/bladeapi/v1alpha1/blade_grpc.pb.go

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

28 changes: 10 additions & 18 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"syscall"
"time"

"github.com/compute-blade-community/compute-blade-agent/internal/agent"
"github.com/compute-blade-community/compute-blade-agent/internal/api"
internal_agent "github.com/compute-blade-community/compute-blade-agent/internal/agent"
"github.com/compute-blade-community/compute-blade-agent/pkg/agent"
"github.com/compute-blade-community/compute-blade-agent/pkg/log"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spechtlabs/go-otel-utils/otelprovider"
Expand Down Expand Up @@ -153,8 +153,8 @@ func main() {
}
}()

log.FromContext(ctx).Info("Bootstrapping compute-blade-agent")
computebladeAgent, err := agent.NewComputeBladeAgent(ctx, cbAgentConfig)
log.FromContext(ctx).Info("Bootstrapping compute-blade-agent", zap.String("version", Version), zap.String("commit", Commit))
computebladeAgent, err := internal_agent.NewComputeBladeAgent(ctx, cbAgentConfig)
if err != nil {
cancelCtx(err)
log.FromContext(ctx).WithError(err).Fatal("Failed to create agent")
Expand All @@ -163,17 +163,6 @@ func main() {
// Run agent
computebladeAgent.RunAsync(ctx, cancelCtx)

// Setup GRPC server
grpcServer := api.NewGrpcApiServer(ctx,
api.WithComputeBladeAgent(computebladeAgent),
api.WithAuthentication(cbAgentConfig.Listen.GrpcAuthenticated),
api.WithListenAddr(cbAgentConfig.Listen.Grpc),
api.WithListenMode(cbAgentConfig.Listen.GrpcListenMode),
)

// Run gRPC API
grpcServer.ServeAsync(ctx, cancelCtx)

// setup prometheus endpoint
promServer := runPrometheusEndpoint(ctx, cancelCtx, &cbAgentConfig.Listen)

Expand All @@ -190,8 +179,11 @@ func main() {
wg.Add(1)
go func() {
defer wg.Done()
otelzap.L().Info("Shutting down grpc server")
grpcServer.GracefulStop()

log.FromContext(ctx).Info("Shutting down compute blade agent...")
if err := computebladeAgent.GracefulStop(ctx); err != nil {
log.FromContext(ctx).WithError(err).Error("Failed to close compute blade agent")
}
}()

// Shut-Down Prometheus Endpoint
Expand All @@ -218,7 +210,7 @@ func main() {
}
}

func runPrometheusEndpoint(ctx context.Context, cancel context.CancelCauseFunc, apiConfig *api.Config) *http.Server {
func runPrometheusEndpoint(ctx context.Context, cancel context.CancelCauseFunc, apiConfig *agent.ApiConfig) *http.Server {
instrumentationHandler := http.NewServeMux()
instrumentationHandler.Handle("/metrics", promhttp.Handler())
instrumentationHandler.HandleFunc("/debug/pprof/", pprof.Index)
Expand Down
Loading
Loading