Skip to content
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
2 changes: 2 additions & 0 deletions cmd/pipecd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ go_library(
"//pkg/app/ops/insightcollector:go_default_library",
"//pkg/app/ops/mysqlensurer:go_default_library",
"//pkg/app/ops/orphancommandcleaner:go_default_library",
"//pkg/cache/cachemetrics:go_default_library",
"//pkg/cache/rediscache:go_default_library",
"//pkg/cli:go_default_library",
"//pkg/config:go_default_library",
Expand All @@ -45,6 +46,7 @@ go_library(
"//pkg/version:go_default_library",
"@com_github_dgrijalva_jwt_go//:go_default_library",
"@com_github_nytimes_gziphandler//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_spf13_cobra//:go_default_library",
"@org_golang_x_sync//errgroup:go_default_library",
"@org_uber_go_zap//:go_default_library",
Expand Down
10 changes: 10 additions & 0 deletions cmd/pipecd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/NYTimes/gziphandler"
jwtgo "github.com/dgrijalva/jwt-go"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/cobra"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
Expand All @@ -38,6 +39,7 @@ import (
"github.com/pipe-cd/pipe/pkg/app/api/pipedverifier"
"github.com/pipe-cd/pipe/pkg/app/api/service/webservice"
"github.com/pipe-cd/pipe/pkg/app/api/stagelogstore"
"github.com/pipe-cd/pipe/pkg/cache/cachemetrics"
"github.com/pipe-cd/pipe/pkg/cache/rediscache"
"github.com/pipe-cd/pipe/pkg/cli"
"github.com/pipe-cd/pipe/pkg/config"
Expand Down Expand Up @@ -130,6 +132,9 @@ func NewServerCommand() *cobra.Command {
}

func (s *server) run(ctx context.Context, t cli.Telemetry) error {
// Register all metrics.
registerMetrics()

group, ctx := errgroup.WithContext(ctx)

// Load control plane configuration from the specified file.
Expand Down Expand Up @@ -478,3 +483,8 @@ func createFilestore(ctx context.Context, cfg *config.ControlPlaneSpec, logger *
return nil, fmt.Errorf("unknown filestore type %q", cfg.Filestore.Type)
}
}

func registerMetrics() {
r := prometheus.DefaultRegisterer
cachemetrics.Register(r)
}
2 changes: 1 addition & 1 deletion manifests/pipecd/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ server:
enableGRPCReflection: false
secureCookie: false
logEncoding: humanize
metrics: false
metrics: true
resources: {}
env: []

Expand Down
9 changes: 9 additions & 0 deletions pkg/cache/cachemetrics/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["metrics.go"],
importpath = "github.com/pipe-cd/pipe/pkg/cache/cachemetrics",
visibility = ["//visibility:public"],
deps = ["@com_github_prometheus_client_golang//prometheus:go_default_library"],
)
62 changes: 62 additions & 0 deletions pkg/cache/cachemetrics/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2021 The PipeCD Authors.
//
// 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.

package cachemetrics

import (
"github.com/prometheus/client_golang/prometheus"
)

const (
statusKey = "status"
sourceKey = "source"
)

type StatusLabel string

const (
LabelStatusHit StatusLabel = "hit"
LabelStatusMiss StatusLabel = "miss"
)

type SourceLabel string

const (
LabelSourceRedis SourceLabel = "redis"
LabelSourceInmemory SourceLabel = "inmemory"
)

var (
getCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "controlplane_cache_get_operation_total",
Copy link
Member

Choose a reason for hiding this comment

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

Is prefix controlplane okay? pipecd is better?

But it's okay to determine later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ops, should be as your suggestion 🙏 lets me address it in this PR 🙏

Copy link
Member

Choose a reason for hiding this comment

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

Oops, already merged lol

Copy link
Member Author

Choose a reason for hiding this comment

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

@nakabonne plz #2157 🙏

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha!

Help: "Number of cache get operation while processing",
},
[]string{
statusKey,
sourceKey,
},
)
)

func Register(r prometheus.Registerer) {
r.MustRegister(getCounter)
}

func IncGetOperationCounter(status StatusLabel, source SourceLabel) {
getCounter.With(prometheus.Labels{
statusKey: string(status),
sourceKey: string(source),
}).Inc()
}
1 change: 1 addition & 0 deletions pkg/cache/rediscache/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/cache:go_default_library",
"//pkg/cache/cachemetrics:go_default_library",
"//pkg/redis:go_default_library",
"@com_github_gomodule_redigo//redis:go_default_library",
],
Expand Down
17 changes: 17 additions & 0 deletions pkg/cache/rediscache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
redigo "github.com/gomodule/redigo/redis"

"github.com/pipe-cd/pipe/pkg/cache"
"github.com/pipe-cd/pipe/pkg/cache/cachemetrics"
"github.com/pipe-cd/pipe/pkg/redis"
)

Expand Down Expand Up @@ -47,16 +48,32 @@ func (c *RedisCache) Get(k interface{}) (interface{}, error) {
reply, err := conn.Do("GET", k)
if err != nil {
if err == redigo.ErrNil {
cachemetrics.IncGetOperationCounter(
cachemetrics.LabelStatusMiss,
cachemetrics.LabelSourceRedis,
)
return nil, cache.ErrNotFound
}
return nil, err
}
if reply == nil {
cachemetrics.IncGetOperationCounter(
cachemetrics.LabelStatusMiss,
cachemetrics.LabelSourceRedis,
)
return nil, cache.ErrNotFound
}
if err, ok := reply.(redigo.Error); ok {
cachemetrics.IncGetOperationCounter(
cachemetrics.LabelStatusMiss,
cachemetrics.LabelSourceRedis,
)
return nil, err
}
cachemetrics.IncGetOperationCounter(
cachemetrics.LabelStatusHit,
cachemetrics.LabelSourceRedis,
)
return reply, nil
}

Expand Down