Skip to content
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

bcs-monitor规范修改golangci-lint #2623

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.2
args: --timeout=30m --issues-exit-code=0
args: --timeout=30m
working-directory: bcs-services/bcs-monitor
bcs-bscp:
name: bcs-bscp
Expand Down
4 changes: 2 additions & 2 deletions bcs-services/bcs-monitor/cmd/bcs-monitor/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* 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.
*
*/

// Package main cmd start
package main

import (
Expand Down Expand Up @@ -63,7 +63,7 @@ func runAPIServer(ctx context.Context, g *run.Group, opt *option) error {
storage.InitStorage()

// 启动 apiserver
g.Add(server.Run, func(err error) { server.Close(); component.GetAuditClient().Close() })
g.Add(server.Run, func(err error) { _ = server.Close(); component.GetAuditClient().Close() })
g.Add(sd.Run, func(error) {})

bcs.CacheListClusters()
Expand Down
16 changes: 10 additions & 6 deletions bcs-services/bcs-monitor/cmd/bcs-monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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.
*
*/

package main
Expand Down Expand Up @@ -67,7 +66,7 @@ type option struct {
g *run.Group
reg *prometheus.Registry
tracer opentracing.Tracer
logger logger.Logger
logger logger.Logger // nolint
ctx context.Context
cancel func()
}
Expand Down Expand Up @@ -118,14 +117,16 @@ func main() {
}

if err := Execute(ctx); err != nil {
os.Exit(1)
stop()
os.Exit(1) // nolint
}

if isPrintVersion() {
os.Exit(0)
stop()
os.Exit(0) // nolint
}

//初始化 Tracer
// 初始化 Tracer
shutdown, errorInitTracing := tracing.InitTracing(config.G.TracingConf)
if errorInitTracing != nil {
logger.Info(errorInitTracing.Error())
Expand All @@ -140,12 +141,15 @@ func main() {

// Running in container with limits but with empty/wrong value of GOMAXPROCS env var could lead to throttling by cpu
// maxprocs will automate adjustment by using cgroups info about cpu limit if it set as value for runtime.GOMAXPROCS.
if _, err := maxprocs.Set(maxprocs.Logger(func(template string, args ...interface{}) { logger.Infof(template, args) })); err != nil {
if _, err := maxprocs.Set(maxprocs.Logger(func(template string, args ...interface{}) {
logger.Infof(template, args)
})); err != nil {
logger.Warnw("Failed to set GOMAXPROCS automatically", "err", err)
}
if err := g.Run(); err != nil && err != ctx.Err() {
// Use %+v for github.com/pkg/errors error to print with stack.
logger.Errorw("err", fmt.Sprintf("%+v", errors.Wrap(err, "run command failed")))
stop()
os.Exit(1)
}

Expand Down
1 change: 0 additions & 1 deletion bcs-services/bcs-monitor/cmd/bcs-monitor/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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.
*
*/

package main
Expand Down
10 changes: 6 additions & 4 deletions bcs-services/bcs-monitor/cmd/bcs-monitor/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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.
*
*/

package main
Expand Down Expand Up @@ -47,8 +46,10 @@ func QueryCmd() *cobra.Command {
runCmd(cmd, runQuery)
}

cmd.Flags().StringArrayVar(&storeList, "store", []string{}, "Addresses of statically configured store endpoints")
cmd.Flags().StringArrayVar(&strictStoreList, "store-strict", []string{}, "Addresses of statically configured store endpoints always used, even if the health check fails")
cmd.Flags().StringArrayVar(&storeList, "store", []string{},
"Addresses of statically configured store endpoints")
cmd.Flags().StringArrayVar(&strictStoreList, "store-strict", []string{},
"Addresses of statically configured store endpoints always used, even if the health check fails")
cmd.Flags().StringArrayVar(&httpSDURLs, "store.http-sd-url", []string{},
"HTTP-based service discovery provides store endpoints")

Expand All @@ -60,7 +61,8 @@ func runQuery(ctx context.Context, g *run.Group, opt *option) error {

logger.Infow("listening for requests and metrics", "service", "query", "address", bindAddress)
addrIPv6 := utils.GetIPv6AddrFromEnv()
queryServer, err := query.NewQueryAPI(ctx, opt.reg, opt.tracer, kitLogger, bindAddress, httpPort, addrIPv6, strictStoreList, storeList, httpSDURLs, g)
queryServer, err := query.NewQueryAPI(ctx, opt.reg, opt.tracer, kitLogger, bindAddress, httpPort, addrIPv6,
strictStoreList, storeList, httpSDURLs, g)
if err != nil {
return errors.Wrap(err, "query")
}
Expand Down
1 change: 0 additions & 1 deletion bcs-services/bcs-monitor/cmd/bcs-monitor/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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.
*
*/

package main
Expand Down
1 change: 0 additions & 1 deletion bcs-services/bcs-monitor/cmd/bcs-monitor/storegw.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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.
*
*/

package main
Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-monitor/pkg/api/logrule/autoclean.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* 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.
*
*/

// Package logrule log rule
package logrule

import (
Expand Down
3 changes: 1 addition & 2 deletions bcs-services/bcs-monitor/pkg/api/logrule/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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.
*
*/

package logrule
Expand Down Expand Up @@ -265,7 +264,7 @@ func (resp *GetLogRuleResp) loadFromBcsLogConfig(logConfig *logv1.BcsLogConfig,
resp.Config.ExtraLabels = append(resp.Config.ExtraLabels, bklog.Label{Key: tagk, Value: tagv})
}
for tagk, tagv := range logConfig.Spec.Selector.MatchLabels {
resp.Config.LogRuleContainer.LabelSelector.MatchLabels = append(resp.Config.ExtraLabels,
resp.Config.LogRuleContainer.LabelSelector.MatchLabels = append(resp.Config.ExtraLabels, // nolint
bklog.Label{Key: tagk, Value: tagv})
}
if logConfig.Spec.WorkloadNamespace != "" {
Expand Down
3 changes: 1 addition & 2 deletions bcs-services/bcs-monitor/pkg/api/logrule/logrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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.
*
*/

package logrule
Expand Down Expand Up @@ -368,7 +367,7 @@ func RetryLogRule(c *rest.Context) (interface{}, error) {
if err != nil {
data.Update(entity.FieldKeyStatus, entity.FailedStatus)
data.Update(entity.FieldKeyMessage, err.Error())
store.UpdateLogRule(c.Context, id, data)
store.UpdateLogRule(c.Context, id, data) // nolint
return nil, err
}

Expand Down
1 change: 1 addition & 0 deletions bcs-services/bcs-monitor/pkg/api/metrics/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* limitations under the License.
*/

// Package metrics api metric
package metrics

import (
Expand Down
22 changes: 14 additions & 8 deletions bcs-services/bcs-monitor/pkg/api/metrics/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import (
"github.com/Tencent/bk-bcs/bcs-services/bcs-monitor/pkg/rest"
)

const (
// CLUSTERID ...
CLUSTERID = `cluster_id="%<clusterId>s", namespace="%<namespace>s", pod_name=~"%<podName>s", ` +
`container_name=~"%<containerName>s", %<provider>s`
)

// ContainerUsageQuery 容器查询参数
type ContainerUsageQuery struct {
UsageQuery `json:",inline"`
Expand Down Expand Up @@ -45,8 +51,8 @@ func handleContainerMetric(c *rest.Context, promql string) (interface{}, error)
"provider": PROVIDER,
}

result, err := bcsmonitor.QueryRange(c.Request.Context(), c.ProjectCode, promql, params, queryTime.Start, queryTime.End,
queryTime.Step)
result, err := bcsmonitor.QueryRange(c.Request.Context(), c.ProjectCode, promql, params, queryTime.Start,
queryTime.End, queryTime.Step)
if err != nil {
return nil, err
}
Expand All @@ -61,7 +67,7 @@ func handleContainerMetric(c *rest.Context, promql string) (interface{}, error)
// @Router /namespaces/namespace/pods/:pod/containers/:container/cpu_usage [GET]
func ContainerCPUUsage(c *rest.Context) (interface{}, error) {
promql :=
`bcs:container:cpu_usage{cluster_id="%<clusterId>s", namespace="%<namespace>s", pod_name=~"%<podName>s", container_name=~"%<containerName>s", %<provider>s}`
`bcs:container:cpu_usage{` + CLUSTERID + `}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种不用处理

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其他类似的也是


return handleContainerMetric(c, promql)

Expand All @@ -74,7 +80,7 @@ func ContainerCPUUsage(c *rest.Context) (interface{}, error) {
// @Router /namespaces/namespace/pods/:pod/containers/:container/memory_used [GET]
func ContainerMemoryUsed(c *rest.Context) (interface{}, error) {
promql :=
`bcs:container:memory_used{cluster_id="%<clusterId>s", namespace="%<namespace>s", pod_name=~"%<podName>s", container_name=~"%<containerName>s", %<provider>s}`
`bcs:container:memory_used{` + CLUSTERID + `}`

return handleContainerMetric(c, promql)
}
Expand All @@ -86,7 +92,7 @@ func ContainerMemoryUsed(c *rest.Context) (interface{}, error) {
// @Router /namespaces/namespace/pods/:pod/containers/:container/cpu_limit [GET]
func ContainerCPULimit(c *rest.Context) (interface{}, error) {
promql :=
`bcs:container:cpu_limit{cluster_id="%<clusterId>s", namespace="%<namespace>s", pod_name=~"%<podName>s", container_name=~"%<containerName>s", %<provider>s}`
`bcs:container:cpu_limit{` + CLUSTERID + `}`

return handleContainerMetric(c, promql)
}
Expand All @@ -98,7 +104,7 @@ func ContainerCPULimit(c *rest.Context) (interface{}, error) {
// @Router /namespaces/namespace/pods/:pod/containers/:container/memory_limit [GET]
func ContainerMemoryLimit(c *rest.Context) (interface{}, error) {
promql :=
`bcs:container:memory_limit{cluster_id="%<clusterId>s", namespace="%<namespace>s", pod_name=~"%<podName>s", container_name=~"%<containerName>s", %<provider>s}`
`bcs:container:memory_limit{` + CLUSTERID + `}`

return handleContainerMetric(c, promql)

Expand All @@ -111,7 +117,7 @@ func ContainerMemoryLimit(c *rest.Context) (interface{}, error) {
// @Router /namespaces/namespace/pods/:pod/containers/:container/disk_read_total [GET]
func ContainerDiskReadTotal(c *rest.Context) (interface{}, error) {
promql :=
`bcs:container:disk_read_total{cluster_id="%<clusterId>s", namespace="%<namespace>s", pod_name=~"%<podName>s", container_name=~"%<containerName>s", %<provider>s}`
`bcs:container:disk_read_total{` + CLUSTERID + `}`

return handleContainerMetric(c, promql)

Expand All @@ -124,7 +130,7 @@ func ContainerDiskReadTotal(c *rest.Context) (interface{}, error) {
// @Router /namespaces/namespace/pods/:pod/containers/:container/disk_write_total [GET]
func ContainerDiskWriteTotal(c *rest.Context) (interface{}, error) {
promql :=
`bcs:container:disk_write_total{cluster_id="%<clusterId>s", namespace="%<namespace>s", pod_name=~"%<podName>s", container_name=~"%<containerName>s", %<provider>s}`
`bcs:container:disk_write_total{` + CLUSTERID + `}`

return handleContainerMetric(c, promql)
}
18 changes: 12 additions & 6 deletions bcs-services/bcs-monitor/pkg/api/metrics/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import (
"github.com/Tencent/bk-bcs/bcs-services/bcs-monitor/pkg/rest"
)

const (
// PODMETRIC ...
PODMETRIC = `cluster_id="%<clusterId>s", namespace="%<namespace>s", ` +
`pod_name=~"%<podNameList>s", %<provider>s`
)

// PodUsageQuery Pod 查询
type PodUsageQuery struct {
UsageQuery `json:",inline"`
Expand All @@ -44,8 +50,8 @@ func handlePodMetric(c *rest.Context, promql string) (interface{}, error) {
"provider": PROVIDER,
}

result, err := bcsmonitor.QueryRange(c.Request.Context(), c.ProjectCode, promql, params, queryTime.Start, queryTime.End,
queryTime.Step)
result, err := bcsmonitor.QueryRange(c.Request.Context(), c.ProjectCode, promql, params, queryTime.Start,
queryTime.End, queryTime.Step)

if err != nil {
return nil, err
Expand All @@ -60,7 +66,7 @@ func handlePodMetric(c *rest.Context, promql string) (interface{}, error) {
// @Router /namespaces/:namespace/pods/cpu_usage [POST]
func PodCPUUsage(c *rest.Context) (interface{}, error) {
promql :=
`bcs:pod:cpu_usage{cluster_id="%<clusterId>s", namespace="%<namespace>s", pod_name=~"%<podNameList>s", %<provider>s}`
`bcs:pod:cpu_usage{` + PODMETRIC + `}`

return handlePodMetric(c, promql)
}
Expand All @@ -72,7 +78,7 @@ func PodCPUUsage(c *rest.Context) (interface{}, error) {
// @Router /namespaces/:namespace/pods/memory_used [POST]
func PodMemoryUsed(c *rest.Context) (interface{}, error) {
promql :=
`bcs:pod:memory_used{cluster_id="%<clusterId>s", namespace="%<namespace>s", pod_name=~"%<podNameList>s", %<provider>s}`
`bcs:pod:memory_used{` + PODMETRIC + `}`

return handlePodMetric(c, promql)
}
Expand All @@ -84,7 +90,7 @@ func PodMemoryUsed(c *rest.Context) (interface{}, error) {
// @Router /namespaces/:namespace/pods/network_receive [POST]
func PodNetworkReceive(c *rest.Context) (interface{}, error) {
promql :=
`bcs:pod:network_receive{cluster_id="%<clusterId>s", namespace="%<namespace>s", pod_name=~"%<podNameList>s", %<provider>s}`
`bcs:pod:network_receive{` + PODMETRIC + `}`

return handlePodMetric(c, promql)
}
Expand All @@ -96,7 +102,7 @@ func PodNetworkReceive(c *rest.Context) (interface{}, error) {
// @Router /namespaces/:namespace/pods/network_transmit [POST]
func PodNetworkTransmit(c *rest.Context) (interface{}, error) {
promql :=
`bcs:pod:network_transmit{cluster_id="%<clusterId>s", namespace="%<namespace>s", pod_name=~"%<podNameList>s", %<provider>s}`
`bcs:pod:network_transmit{` + PODMETRIC + `}`

return handlePodMetric(c, promql)
}
5 changes: 2 additions & 3 deletions bcs-services/bcs-monitor/pkg/api/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
* 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.
*
*/

// Package pod xxx
// Package pod pod operate
package pod

import (
Expand Down Expand Up @@ -89,7 +88,7 @@ func DownloadPodLog(c *rest.Context) {
}

// 下载参数
logQuery.TailLines = int64(k8sclient.MAX_TAIL_LINES)
logQuery.TailLines = k8sclient.MAX_TAIL_LINES
logQuery.LimitBytes = int64(k8sclient.MAX_LIMIT_BYTES)

logs, err := k8sclient.GetPodLogByte(c.Request.Context(), clusterId, namespace, pod, logQuery)
Expand Down
3 changes: 1 addition & 2 deletions bcs-services/bcs-monitor/pkg/api/pod/sse.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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.
*
*/

package pod
Expand Down Expand Up @@ -39,7 +38,7 @@ const (
// @Produce text/event-stream
// @Success 200 {string} string
// @Router /namespaces/:namespace/pods/:pod/logs/stream [get]
func PodLogStream(c *rest.Context) {
func PodLogStream(c *rest.Context) { // nolint
clusterId := c.Param("clusterId")
namespace := c.Param("namespace")
pod := c.Param("pod")
Expand Down
Loading
Loading