Skip to content

Commit

Permalink
Pr/welan/update1 (#367)
Browse files Browse the repository at this point in the history
* golang

Signed-off-by: [email protected] <[email protected]>

* dsa

Signed-off-by: weizhoublue <[email protected]>

* otel

Signed-off-by: [email protected] <[email protected]>

* a

Signed-off-by: [email protected] <[email protected]>

* sadf

Signed-off-by: [email protected] <[email protected]>

* d

Signed-off-by: [email protected] <[email protected]>

* d

Signed-off-by: [email protected] <[email protected]>

* update golang and sdk

Signed-off-by: weizhoublue <[email protected]>

---------

Signed-off-by: [email protected] <[email protected]>
Signed-off-by: weizhoublue <[email protected]>
  • Loading branch information
weizhoublue authored Feb 18, 2024
1 parent 207b2e2 commit 8694e6a
Show file tree
Hide file tree
Showing 730 changed files with 40,273 additions and 10,200 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/call-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- name: Setup Golang
uses: actions/setup-go@v4
with:
go-version: '1.20.0'
go-version: 1.21.7
id: go

# https://github.com/helm/kind-action
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint-golang.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.20.0'
go-version: 1.21.7

- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -119,7 +119,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.20.0'
go-version: 1.21.7

- name: Checkout code
uses: actions/checkout@v3
Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.20.0'
go-version: 1.21.7

- name: Checkout code
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/oss-fuzz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.20.0'
go-version: 1.21.7

- name: run
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/score-oss-fuzz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.20.0'
go-version: 1.21.7

- name: run
run: |
Expand Down
4 changes: 2 additions & 2 deletions Makefile.defs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

GO_VERSION := 1.20
GO_VERSION := 1.21.7

REGISTER ?= ghcr.io
GIT_REPO ?= spidernet-io/rocktemplate
Expand Down Expand Up @@ -146,7 +146,7 @@ endif

#====== pyroscope
PYROSCOPE_CONTAINER_NAME := pyroscope
PYROSCOPE_IMAGE_NAME := pyroscope/pyroscope:latest
PYROSCOPE_IMAGE_NAME := grafana/pyroscope:latest
# empty to disable PYROSCOPE
# PYROSCOPE_LOCAL_PORT :=
PYROSCOPE_LOCAL_PORT := 8040
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1.2
v0.1.0
6 changes: 3 additions & 3 deletions charts/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apiVersion: v2
name: rocktemplate
home: "https://spidernet-io.github.io/agent"
home: "https://github.com/spidernet-io/rocktemplate"
# application or library
type: application
# no need to modify this version , CI will auto update it with /VERSION
version: 0.1.2
version: 0.1.0
# This field is informational, and has no impact on chart version calculations .
# Leaving it unquoted can lead to parsing issues in some cases
# no need to modify this version , CI will auto update it with /VERSION
appVersion: "0.1.2"
appVersion: "0.1.0"
kubeVersion: ">= 1.16.0-0"
description: rocktemplate
sources:
Expand Down
33 changes: 13 additions & 20 deletions cmd/agent/cmd/metricServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ package cmd
import (
pkgmetric "github.com/spidernet-io/rocktemplate/pkg/metrics"
"github.com/spidernet-io/rocktemplate/pkg/types"
"go.opentelemetry.io/otel/metric/instrument/syncfloat64"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"

api "go.opentelemetry.io/otel/metric"

"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/metric/aggregation"
"go.opentelemetry.io/otel/sdk/metric/view"
)

var (
MetricCounterRequest syncfloat64.Counter
MetricGaugeEndpoint syncfloat64.UpDownCounter
MetricHistogramDuration syncfloat64.Histogram
MetricCounterRequest api.Int64Counter
MetricGaugeEndpoint api.Int64UpDownCounter
MetricHistogramDuration api.Float64Histogram
)

var metricMapping = []pkgmetric.MetricMappingType{
Expand All @@ -30,20 +31,12 @@ func RunMetricsServer(meterName string) {
logger := rootLogger.Named("metric")

// View to customize histogram buckets
customBucketsView, err := view.New(
// MatchInstrumentName will match an instrument based on the its name.
// This will accept wildcards of * for zero or more characters, and ? for
// exactly one character. A name of "*" (default) will match all instruments.
view.MatchInstrumentName("*duration*"),
view.MatchInstrumentationScope(instrumentation.Scope{Name: meterName}),
// With* to modify instruments
view.WithSetAggregation(aggregation.ExplicitBucketHistogram{
Boundaries: []float64{1, 10, 20, 50},
}),
)
if err != nil {
logger.Sugar().Fatalf("failed to generate view, reason=%v", err)
}
customBucketsView := sdkmetric.NewView(sdkmetric.Instrument{
Name: "*duration*",
Scope: instrumentation.Scope{Name: meterName},
}, sdkmetric.Stream{Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
Boundaries: []float64{1, 10, 20, 50},
}})

// globalMeter=pkgmetric.NewMetricsServer(meterName, globalConfig.MetricPort, metricMapping, customBucketsView, logger)
pkgmetric.RunMetricsServer(types.AgentConfig.EnableMetric, meterName, types.AgentConfig.MetricPort, metricMapping, customBucketsView, logger)
Expand Down
14 changes: 6 additions & 8 deletions cmd/controller/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spidernet-io/rocktemplate/pkg/mybookManager"
"github.com/spidernet-io/rocktemplate/pkg/types"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"path/filepath"
"time"
)
Expand Down Expand Up @@ -41,14 +42,11 @@ func DaemonMain() {
MetricGaugeEndpoint.Add(context.Background(), -10)
MetricGaugeEndpoint.Add(context.Background(), 5)

attrs := []attribute.KeyValue{
attribute.Key("pod1").String("value1"),
}
MetricCounterRequest.Add(context.Background(), 10, attrs...)
attrs = []attribute.KeyValue{
attribute.Key("pod2").String("value1"),
}
MetricCounterRequest.Add(context.Background(), 5, attrs...)
attrs := attribute.NewSet(attribute.String("pod1", "value1"), attribute.Int("version", 1))
MetricCounterRequest.Add(context.Background(), 10, metric.WithAttributeSet(attrs))

attrs = attribute.NewSet(attribute.String("pod2", "value1"), attribute.Int("version", 1))
MetricCounterRequest.Add(context.Background(), 5, metric.WithAttributeSet(attrs))

MetricHistogramDuration.Record(context.Background(), 10)
MetricHistogramDuration.Record(context.Background(), 20)
Expand Down
40 changes: 20 additions & 20 deletions cmd/controller/cmd/metricServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ package cmd
import (
pkgmetric "github.com/spidernet-io/rocktemplate/pkg/metrics"
"github.com/spidernet-io/rocktemplate/pkg/types"
"go.opentelemetry.io/otel/metric/instrument/syncfloat64"
api "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/metric/aggregation"
"go.opentelemetry.io/otel/sdk/metric/view"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
)

// https://pkg.go.dev/go.opentelemetry.io/otel/metric#hdr-Instruments
/*
All synchronous instruments (Int64Counter, Int64UpDownCounter, Int64Histogram, Float64Counter, Float64UpDownCounter, and Float64Histogram) are used to measure the operation and performance of source code during the source code execution. These instruments only make measurements when the source code they instrument is run.
All asynchronous instruments (Int64ObservableCounter, Int64ObservableUpDownCounter, Int64ObservableGauge, Float64ObservableCounter, Float64ObservableUpDownCounter, and Float64ObservableGauge) are used to measure metrics outside of the execution of source code. They are said to make "observations" via a callback function called once every measurement collection cycle.
*/
var (
MetricCounterRequest syncfloat64.Counter
MetricGaugeEndpoint syncfloat64.UpDownCounter
MetricHistogramDuration syncfloat64.Histogram
MetricCounterRequest api.Int64Counter
MetricGaugeEndpoint api.Int64UpDownCounter
MetricHistogramDuration api.Float64Histogram
)

var metricMapping = []pkgmetric.MetricMappingType{
Expand All @@ -29,22 +34,17 @@ func RunMetricsServer(meterName string) {
logger := rootLogger.Named("metric")

// View to customize histogram buckets
customBucketsView, err := view.New(
// MatchInstrumentName will match an instrument based on the its name.
// This will accept wildcards of * for zero or more characters, and ? for
// exactly one character. A name of "*" (default) will match all instruments.
view.MatchInstrumentName("*duration*"),
view.MatchInstrumentationScope(instrumentation.Scope{Name: meterName}),
// With* to modify instruments
view.WithSetAggregation(aggregation.ExplicitBucketHistogram{
Boundaries: []float64{1, 10, 20, 50},
}),
)
if err != nil {
logger.Sugar().Fatalf("failed to generate view, reason=%v", err)
customBucketsView := sdkmetric.NewView(sdkmetric.Instrument{
Name: "*duration*",
Scope: instrumentation.Scope{Name: meterName},
}, sdkmetric.Stream{Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
Boundaries: []float64{1, 10, 20, 50},
}})

if customBucketsView == nil {
logger.Sugar().Fatalf("failed to generate view")
}

// globalMeter = pkgmetric.NewMetricsServer(meterName, globalConfig.MetricPort, metricMapping, customBucketsView, logger)
pkgmetric.RunMetricsServer(types.ControllerConfig.EnableMetric, meterName, types.ControllerConfig.MetricPort, metricMapping, customBucketsView, logger)

}
21 changes: 13 additions & 8 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@

## copy

1. copy repo
1. copy repo `cp -rf rocktemplate/* YourRepoName && cp rocktemplate/.gitignore YourRepoName && cp rocktemplate/.github YourRepoName `

replace all 'rocktemplate' to 'YourRepoName'

replace all 'spidernet-io' and 'spidernet.io' to 'YourOrigin'

replace all 'Copyright 2022' to be the right time

2. grep "====modify====" * -RHn --colour and modify all of them

3. update api/v1/openapi.yaml and `make update_openapi_sdk`
3. in a linux machine, update api/v1/openapi.yaml and `make update_openapi_sdk`

4. redefine CRD in pkg/k8s/v1
rename directory name 'pkg/k8s/v1/rocktemplate.spidernet.io'
rename directory name 'pkg/k8s/apis/rocktemplate.spidernet.io'
replace all 'mybook' to 'YourCRDName'
and `make update_crd_sdk`, and code pkg/mybookManager
and `make update_crd_sdk`, and write code in pkg/mybookManager

rename pkg/mybookManager and replace all 'mybook' with your CRD name in this directory

rm charts/crds/rocktemplate.spidernet.io_mybooks.yaml

in repo: replace all "github.com/spidernet-io/spiderdoctor/pkg/mybookManager" to "github.com/spidernet-io/spiderdoctor/pkg/${crdName}Manager"
in repo: find and replace all "mybook" to YourCrd
# in repo: replace all "github.com/spidernet-io/spiderdoctor/pkg/mybookManager" to "github.com/spidernet-io/spiderdoctor/pkg/${crdName}Manager"
# in repo: find and replace all "mybook" to YourCrd

5. update charts/ , and images/ , and CODEOWNERS

Expand Down Expand Up @@ -83,8 +85,6 @@
12. build base image ,
update BASE_IMAGE in images/agent/Dockerfile and images/controller/Dockerfile
run test



## local develop

Expand Down Expand Up @@ -113,3 +113,8 @@

helm repo add rock https://spidernet-io.github.io/rocktemplate/

## upgrade project

1. golang version: edit golang version in Makefile.defs and `make update_go_version`

2. 更新所有包 go get -u ./...
37 changes: 36 additions & 1 deletion docs/develop/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,43 @@

3. `make e2e_run`

4. check proscope, browser vists http://NodeIP:4040
4. check proscope, browser visits http://NodeIP:4040

5. check metric,

## chart develop

helm repo add rocktemplate https://spidernet-io.github.io/rocktemplate

## test


```shell

cat <<EOF > mybook1.yaml
apiVersion: rocktemplate.spidernet.io/v1
kind: Mybook
metadata:
name: test1
spec:
ipVersion: 4
subnet: "1.0.0.0/8"
EOF

kubectl apply -f mybook1.yaml


cat <<EOF > mybook2.yaml
apiVersion: rocktemplate.spidernet.io/v1
kind: Mybook
metadata:
name: test2
spec:
ipVersion: 4
subnet: "2.0.0.0/8"
EOF

kubectl apply -f mybook2.yaml


```
Loading

0 comments on commit 8694e6a

Please sign in to comment.