-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat:add vlogs server feat:websocket and auto shutdown server. feat: devbox websocket. fix vlogs bug.
- Loading branch information
1 parent
e1e7c94
commit 3f89c54
Showing
16 changed files
with
628 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ use ( | |
./launchpad | ||
./pay | ||
./devbox | ||
./vlogs | ||
) | ||
|
||
replace ( | ||
|
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,7 @@ | ||
FROM gcr.io/distroless/static:nonroot | ||
ARG TARGETARCH | ||
COPY bin/service-vlogs-$TARGETARCH /manager | ||
EXPOSE 8428 | ||
USER 65532:65532 | ||
|
||
ENTRYPOINT [ "/manager", "config/config.yml" ] |
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,55 @@ | ||
IMG ?= ghcr.io/labring/sealos-vlogs-service:latest | ||
|
||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
GOBIN=$(shell go env GOPATH)/bin | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
# only support linux, non cgo | ||
PLATFORMS ?= linux_arm64 linux_amd64 | ||
GOOS=linux | ||
CGO_ENABLED=0 | ||
GOARCH=$(shell go env GOARCH) | ||
|
||
GO_BUILD_FLAGS=-trimpath -ldflags "-s -w" | ||
|
||
.PHONY: all | ||
all: build | ||
|
||
##@ General | ||
|
||
# The help target prints out all targets with their descriptions organized | ||
# beneath their categories. The categories are represented by '##@' and the | ||
# target descriptions by '##'. The awk commands is responsible for reading the | ||
# entire set of makefiles included in this invocation, looking for lines of the | ||
# file as xyz: ## something, and then pretty-format the target and help. Then, | ||
# if there's a line with ##@ something, that gets pretty-printed as a category. | ||
# More info on the usage of ANSI control characters for terminal formatting: | ||
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters | ||
# More info on the awk command: | ||
# http://linuxcommand.org/lc3_adv_awk.php | ||
|
||
.PHONY: help | ||
help: ## Display this help. | ||
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | ||
|
||
##@ Build | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f $(SERVICE_NAME) | ||
|
||
.PHONY: build | ||
build: clean ## Build service-hub binary. | ||
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) go build $(GO_BUILD_FLAGS) -o bin/manager main.go | ||
|
||
.PHONY: docker-build | ||
docker-build: build | ||
mv bin/manager bin/service-vlogs-${TARGETARCH} | ||
docker build -t $(IMG) . | ||
|
||
.PHONY: docker-push | ||
docker-push: | ||
docker push $(IMG) |
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,54 @@ | ||
# RESTServer | ||
|
||
## Description | ||
|
||
restserver for victoria logs | ||
|
||
## Getting Started | ||
|
||
### Running on the cluster | ||
|
||
1. Build and push your image to the location specified by `IMG`: | ||
|
||
```sh | ||
make docker-build docker-push IMG=<some-registry>/sealos-vlogs-service:latest | ||
``` | ||
|
||
2. Deploy the restserver: | ||
|
||
```sh | ||
kubectl apply -f deploy/manifests/ | ||
``` | ||
|
||
### How it works | ||
|
||
To enable the database frontend application to retrieve monitoring data, you need to modify the environment variable `MONITOR_URL` of the frontend deployment to the corresponding address of the restserver. | ||
|
||
Additionally, to configure the data source, you need to set the environment variable `VM_SERVICE_HOST` of the restserver deployment to the correct address. | ||
|
||
``` | ||
e.g. | ||
http://prometheus.sealos.svc.cluster.local | ||
``` | ||
|
||
## License | ||
|
||
Copyright 2023. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
|
||
you may not use this file except in compliance with the License. | ||
|
||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
|
||
distributed under the License is distributed on an "AS IS" BASIS, | ||
|
||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
|
||
See the License for the specific language governing permissions and | ||
|
||
limitations under the License. |
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,2 @@ | ||
server: | ||
addr: ":8428" |
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,5 @@ | ||
FROM scratch | ||
COPY registry registry | ||
COPY manifests manifests | ||
|
||
CMD ["kubectl apply -f manifests/deploy.yaml"] |
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,16 @@ | ||
### docker image build and deploy | ||
```bash | ||
make docker-build IMG=$(YourImageName) | ||
# edit deploy/manifests/depoly.yaml and deploy | ||
kubectl apply -f deploy/manifests/depoly.yaml | ||
``` | ||
|
||
### cluster image build and deploy | ||
```bash | ||
``` | ||
|
||
### Victoria Metrics | ||
|
||
In order to prevent performance degradation or abnormal behavior caused by excessive data size in Prometheus, VictoriaMetrics is utilized for data collection. | ||
|
||
> By default, we use kb-prometheus-server for the data collection service. |
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,86 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
labels: | ||
app: service-vlogs | ||
name: service-vlogs-config | ||
namespace: sealos | ||
data: | ||
config.yml: | | ||
server: | ||
addr: ":8428" | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: service-vlogs | ||
name: service-vlogs-deployment | ||
namespace: sealos | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: service-vlogs | ||
strategy: | ||
type: Recreate | ||
template: | ||
metadata: | ||
labels: | ||
app: service-vlogs | ||
spec: | ||
containers: | ||
- args: | ||
- /config/config.yml | ||
command: | ||
- /manager | ||
image: ghcr.io/labring/sealos-vlogs-service:latest | ||
imagePullPolicy: Always | ||
name: service-vlogs | ||
ports: | ||
- containerPort: 8428 | ||
protocol: TCP | ||
resources: | ||
limits: | ||
cpu: 500m | ||
memory: 1Gi | ||
requests: | ||
cpu: 5m | ||
memory: 64Mi | ||
securityContext: | ||
allowPrivilegeEscalation: false | ||
capabilities: | ||
drop: | ||
- ALL | ||
runAsNonRoot: true | ||
terminationMessagePath: /dev/termination-log | ||
terminationMessagePolicy: File | ||
env: | ||
- name: WHITELIST_KUBERNETES_HOSTS | ||
value: "https://usw.sailos.io:6443" | ||
volumeMounts: | ||
- mountPath: /config | ||
name: config-vol | ||
dnsPolicy: ClusterFirst | ||
restartPolicy: Always | ||
volumes: | ||
- configMap: | ||
defaultMode: 420 | ||
name: service-vlogs-config | ||
name: config-vol | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
app: service-vlogs | ||
name: service-vlogs | ||
namespace: sealos | ||
spec: | ||
ports: | ||
- name: http | ||
port: 8428 | ||
protocol: TCP | ||
targetPort: 8428 | ||
selector: | ||
app: service-vlogs |
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,10 @@ | ||
module github.com/labring/sealos/service/vlogs | ||
|
||
go 1.22.7 | ||
|
||
require ( | ||
github.com/labring/sealos/service v0.0.0 | ||
gopkg.in/yaml.v2 v2.4.0 | ||
) | ||
|
||
replace github.com/labring/sealos/service => ../ |
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,63 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net" | ||
"net/http" | ||
"os" | ||
|
||
vlogsServer "github.com/labring/sealos/service/vlogs/server" | ||
) | ||
|
||
type RestartableServer struct { | ||
configFile string | ||
} | ||
|
||
func (rs *RestartableServer) Serve(c *vlogsServer.Config) { | ||
var vs, err = vlogsServer.NewVLogsServer(c) | ||
if err != nil { | ||
fmt.Printf("Failed to create auth server: %s\n", err) | ||
return | ||
} | ||
|
||
hs := &http.Server{ | ||
Addr: c.Server.ListenAddress, | ||
Handler: vs, | ||
} | ||
|
||
var listener net.Listener | ||
listener, err = net.Listen("tcp", c.Server.ListenAddress) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
fmt.Printf("Serve on %s\n", c.Server.ListenAddress) | ||
if err := hs.Serve(listener); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
} | ||
|
||
func main() { | ||
log.SetOutput(os.Stdout) | ||
log.SetFlags(log.LstdFlags | log.Lshortfile) | ||
flag.Parse() | ||
|
||
cf := flag.Arg(0) | ||
if cf == "" { | ||
fmt.Println("Config file not sepcified") | ||
return | ||
} | ||
|
||
config, err := vlogsServer.InitConfig(cf) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
rs := RestartableServer{ | ||
configFile: cf, | ||
} | ||
rs.Serve(config) | ||
} |
Oops, something went wrong.