Skip to content

Commit

Permalink
Implement necoperf-daemon (#6)
Browse files Browse the repository at this point in the history
* Implement necoperf-daemon

Signed-off-by: zeroalphat <taichi-takemura@cybozu.co.jp>
  • Loading branch information
zeroalphat authored Oct 2, 2023
1 parent 0023aea commit 2da88b6
Show file tree
Hide file tree
Showing 19 changed files with 1,552 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- 'main'
env:
go-version: "1.20"
go-version: "1.21"
jobs:
test:
name: Small tests
Expand Down
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MDBOOK := $(BIN_DIR)/mdbook

# Test tools
PROTOC := PATH=$(PWD)/bin:'$(PATH)' $(PWD)/bin/protoc -I=$(PWD)/include:.
PROTOC_OUTPUTS = pkg/rpc/necoperf.pb.go pkg/rpc/necoperf_grpc.pb.go docs/necoperf-grpc.md
PROTOC_OUTPUTS = internal/rpc/necoperf.pb.go internal/rpc/necoperf_grpc.pb.go docs/necoperf-grpc.md
STATICCHECK = $(BIN_DIR)/staticcheck

.PHONY: all
Expand All @@ -21,6 +21,10 @@ book: $(MDBOOK)
rm -rf docs/book
cd docs; $(MDBOOK) build

.PHONY: build
build:
mkdir -p bin
GOBIN=$(BIN_DIR) go install ./cmd/...

.PHONY: test
test:
Expand All @@ -40,13 +44,13 @@ test-go: test-tools
generate:
$(MAKE) $(PROTOC_OUTPUTS)

pkg/rpc/necoperf.pb.go: pkg/rpc/necoperf.proto
internal/rpc/necoperf.pb.go: internal/rpc/necoperf.proto
$(PROTOC) --go_out=module=github.com/cybozu-go/necoperf:. $<

pkg/rpc/necoperf_grpc.pb.go: pkg/rpc/necoperf.proto
internal/rpc/necoperf_grpc.pb.go: internal/rpc/necoperf.proto
$(PROTOC) --go-grpc_out=module=github.com/cybozu-go/necoperf:. $<

docs/necoperf-grpc.md: pkg/rpc/necoperf.proto
docs/necoperf-grpc.md: internal/rpc/necoperf.proto
$(PROTOC) --doc_out=docs --doc_opt=markdown,$@ $<

##@ Tools
Expand Down
37 changes: 37 additions & 0 deletions cmd/necoperf-daemon/cmd/daemon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cmd

import (
"log/slog"
"os"

"github.com/cybozu-go/necoperf/internal/daemon"
"github.com/spf13/cobra"
)

var (
port int
runtimeEndpoint string
workDir string
)

func NewDaemonCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "daemon",
Short: "Starts the daemon",
RunE: func(cmd *cobra.Command, args []string) error {
handler := slog.NewTextHandler(os.Stderr, nil)
logger := slog.New(handler)
daemon, err := daemon.New(logger, port, runtimeEndpoint, workDir)
if err != nil {
return err
}

return daemon.Start()
},
}
cmd.Flags().IntVar(&port, "port", 6543, "Set server port number")
cmd.Flags().StringVar(&runtimeEndpoint, "runtime-endpoint", "unix:///run/containerd/containerd.sock", "Set container runtime endpoint")
cmd.Flags().StringVar(&workDir, "work-dir", "/var/necoperf", "Set working directory")

return cmd
}
26 changes: 26 additions & 0 deletions cmd/necoperf-daemon/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cmd

import (
"log"

"github.com/spf13/cobra"
)

func NewRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "necoperf-daemon",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}

return cmd
}

func Execute() {
rootCmd := NewRootCommand()
rootCmd.AddCommand(NewDaemonCommand())
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}
}
9 changes: 9 additions & 0 deletions cmd/necoperf-daemon/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"github.com/cybozu-go/necoperf/cmd/necoperf-daemon/cmd"
)

func main() {
cmd.Execute()
}
6 changes: 3 additions & 3 deletions docs/necoperf-grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## Table of Contents

- [pkg/rpc/necoperf.proto](#pkg_rpc_necoperf-proto)
- [internal/rpc/necoperf.proto](#internal_rpc_necoperf-proto)
- [PerfProfileRequest](#necoperf-PerfProfileRequest)
- [PerfProfileResponse](#necoperf-PerfProfileResponse)

Expand All @@ -13,10 +13,10 @@



<a name="pkg_rpc_necoperf-proto"></a>
<a name="internal_rpc_necoperf-proto"></a>
<p align="right"><a href="#top">Top</a></p>

## pkg/rpc/necoperf.proto
## internal/rpc/necoperf.proto



Expand Down
95 changes: 95 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
module github.com/cybozu-go/necoperf

go 1.21

toolchain go1.21.1

require (
github.com/google/uuid v1.3.0
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0
github.com/oklog/run v1.1.0
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
golang.org/x/sync v0.3.0
google.golang.org/grpc v1.58.1
google.golang.org/protobuf v1.31.0
k8s.io/cri-api v0.28.2
k8s.io/kubernetes v1.28.2
)

require (
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.35.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.35.1 // indirect
go.opentelemetry.io/otel v1.10.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.10.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.10.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.10.0 // indirect
go.opentelemetry.io/otel/metric v0.31.0 // indirect
go.opentelemetry.io/otel/sdk v1.10.0 // indirect
go.opentelemetry.io/otel/trace v1.10.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.9.3 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.28.2 // indirect
k8s.io/apiextensions-apiserver v0.28.0 // indirect
k8s.io/apimachinery v0.28.2 // indirect
k8s.io/apiserver v0.28.1 // indirect
k8s.io/client-go v0.28.1 // indirect
k8s.io/component-base v0.28.1 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 2da88b6

Please sign in to comment.