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

register cloud events metrics. #217

Merged
merged 2 commits into from
Nov 19, 2024
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
7 changes: 7 additions & 0 deletions cmd/maestro/agent/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,25 @@ import (
"github.com/spf13/pflag"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
utilflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/metrics/legacyregistry"
"k8s.io/component-base/version"
ocmfeature "open-cluster-management.io/api/feature"
commonoptions "open-cluster-management.io/ocm/pkg/common/options"
"open-cluster-management.io/ocm/pkg/features"
"open-cluster-management.io/ocm/pkg/work/spoke"
"open-cluster-management.io/sdk-go/pkg/cloudevents/generic"
)

var (
commonOptions = commonoptions.NewAgentOptions()
agentOption = spoke.NewWorkloadAgentOptions()
)

func init() {
// register the cloud events metrics for the agent
generic.RegisterCloudEventsMetrics(legacyregistry.Registerer())
}

// by default uses 1M as the limit for state feedback
const maxJSONRawLength int32 = 1024 * 1024

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ require (
k8s.io/klog/v2 v2.130.1
open-cluster-management.io/api v0.15.0
open-cluster-management.io/ocm v0.15.0
open-cluster-management.io/sdk-go v0.15.1-0.20241031061311-f50d6e83dae3
open-cluster-management.io/sdk-go v0.15.1-0.20241118094717-4b0d20455f47
sigs.k8s.io/yaml v1.4.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,8 @@ open-cluster-management.io/api v0.15.0 h1:lRee1KOlGHZb2scTA7ff9E9Fxt2hJc7jpkHnaC
open-cluster-management.io/api v0.15.0/go.mod h1:9erZEWEn4bEqh0nIX2wA7f/s3KCuFycQdBrPrRzi0QM=
open-cluster-management.io/ocm v0.15.0 h1:anXQzvQUhM/DT8FcKVi4n8AY97IA5DVI0mb8R1wsvbs=
open-cluster-management.io/ocm v0.15.0/go.mod h1:d6ubRiBaouiQ+yV+wFAmarpU7I77nXhkJnQJf8gLZC4=
open-cluster-management.io/sdk-go v0.15.1-0.20241031061311-f50d6e83dae3 h1:Dw10oC4N54TJDYt9c8SyRD0du80aS3MSvvBUFWlZyTI=
open-cluster-management.io/sdk-go v0.15.1-0.20241031061311-f50d6e83dae3/go.mod h1:fi5WBsbC5K3txKb8eRLuP0Sim/Oqz/PHX18skAEyjiA=
open-cluster-management.io/sdk-go v0.15.1-0.20241118094717-4b0d20455f47 h1:1gNvY3quZ6CWeXnwCLAXuEoNjGGZL+U4uS79vuo8API=
open-cluster-management.io/sdk-go v0.15.1-0.20241118094717-4b0d20455f47/go.mod h1:fi5WBsbC5K3txKb8eRLuP0Sim/Oqz/PHX18skAEyjiA=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0 h1:/U5vjBbQn3RChhv7P11uhYvCSm5G2GaIi5AIGBS6r4c=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0/go.mod h1:z7+wmGM2dfIiLRfrC6jb5kV2Mq/sK1ZP303cxzkV5Y4=
sigs.k8s.io/controller-runtime v0.18.5 h1:nTHio/W+Q4aBlQMgbnC5hZb4IjIidyrizMai9P6n4Rk=
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/cloudevents/source_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/openshift-online/maestro/pkg/api"
"github.com/openshift-online/maestro/pkg/logger"
"github.com/openshift-online/maestro/pkg/services"
"github.com/prometheus/client_golang/prometheus"
cegeneric "open-cluster-management.io/sdk-go/pkg/cloudevents/generic"
ceoptions "open-cluster-management.io/sdk-go/pkg/cloudevents/generic/options"
cetypes "open-cluster-management.io/sdk-go/pkg/cloudevents/generic/types"
Expand Down Expand Up @@ -42,7 +43,7 @@ func NewSourceClient(sourceOptions *ceoptions.CloudEventsSourceOptions, resource
}

// register resource resync metrics for cloud event source client
cegeneric.RegisterResourceResyncMetrics()
cegeneric.RegisterCloudEventsMetrics(prometheus.DefaultRegisterer)
Copy link
Contributor

Choose a reason for hiding this comment

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

what is different between legacyregistry and prometheus.DefaultRegisterer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

legacyregistry is used by maestro-agent with library-go to register metrics, and prometheus.DefaultRegisterer is typically used with the Prometheus SDK to register metrics.


return &SourceClientImpl{
Codec: codec,
Expand Down
20 changes: 20 additions & 0 deletions test/integration/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ func TestResourcePost(t *testing.T) {
Expect(contentStatus["availableReplicas"]).To(Equal(float64(1)))
Expect(contentStatus["readyReplicas"]).To(Equal(float64(1)))
Expect(contentStatus["updatedReplicas"]).To(Equal(float64(1)))

// check the metrics
time.Sleep(1 * time.Second)
families := getServerMetrics(t, "http://localhost:8080/metrics")
labels := []*prommodel.LabelPair{
{Name: strPtr("source"), Value: strPtr("maestro")},
{Name: strPtr("cluster"), Value: strPtr(clusterName)},
{Name: strPtr("type"), Value: strPtr("io.open-cluster-management.works.v1alpha1.manifests")},
}
checkServerCounterMetric(t, families, "cloudevents_sent_total", labels, 3.0)
checkServerCounterMetric(t, families, "cloudevents_received_total", labels, 3.0)
}

func TestResourcePostWithoutName(t *testing.T) {
Expand Down Expand Up @@ -777,6 +788,7 @@ func TestResourceFromGRPC(t *testing.T) {
}, 10*time.Second, 1*time.Second).Should(Succeed())

// check the metrics
time.Sleep(1 * time.Second)
families := getServerMetrics(t, "http://localhost:8080/metrics")
labels := []*prommodel.LabelPair{
{Name: strPtr("type"), Value: strPtr("Publish")},
Expand Down Expand Up @@ -807,6 +819,14 @@ func TestResourceFromGRPC(t *testing.T) {
{Name: strPtr("code"), Value: strPtr("OK")},
}
checkServerCounterMetric(t, families, "grpc_server_processed_total", labels, 0.0)

labels = []*prommodel.LabelPair{
{Name: strPtr("source"), Value: strPtr("maestro")},
{Name: strPtr("cluster"), Value: strPtr(clusterName)},
{Name: strPtr("type"), Value: strPtr("io.open-cluster-management.works.v1alpha1.manifestbundles")},
}
checkServerCounterMetric(t, families, "cloudevents_sent_total", labels, 3.0)
checkServerCounterMetric(t, families, "cloudevents_received_total", labels, 3.0)
}

func TestResourceBundleFromGRPC(t *testing.T) {
Expand Down
Loading