Skip to content

Commit

Permalink
add /v1/metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Achooo committed Apr 27, 2023
1 parent 5eac1d0 commit fb8897d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion agent/hcp/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func verifyCCMRegistration(ctx context.Context, client hcpclient.Client) (string
}

// The endpoint from the HCP gateway is a domain without scheme, so it must be added.
url, err := url.Parse(fmt.Sprintf("https://%s", endpoint))
url, err := url.Parse(fmt.Sprintf("https://%s/v1/metrics", endpoint))
if err != nil {
return "", fmt.Errorf("failed to parse url: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions agent/hcp/deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestVerifyCCMRegistration(t *testing.T) {
}, nil)
},
mockCloudCfg: &client.MockCloudCfg{},
expectedURL: "https://test.com",
expectedURL: "https://test.com/v1/metrics",
},
"successMetricsEndpointOverride": {
expect: func(mockClient *client.MockClient) {
Expand All @@ -74,7 +74,7 @@ func TestVerifyCCMRegistration(t *testing.T) {
}, nil)
},
mockCloudCfg: &client.MockCloudCfg{},
expectedURL: "https://override.com",
expectedURL: "https://override.com/v1/metrics",
},
} {
t.Run(name, func(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions agent/hcp/telemetry/otel_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (o *OTELSink) IncrCounter(key []string, val float32) {
// AddSampleWithLabels emits a Consul gauge metric that gets
// registed by an OpenTelemetry Histogram instrument.
func (o *OTELSink) SetGaugeWithLabels(key []string, val float32, labels []gometrics.Label) {
k := o.flattenKey(key, labels)
k := o.flattenKey(key)

// Set value in global Gauge store.
globalGauges.Store(k, float64(val), toAttributes(labels))
Expand All @@ -113,7 +113,7 @@ func (o *OTELSink) SetGaugeWithLabels(key []string, val float32, labels []gometr

// AddSampleWithLabels emits a Consul sample metric that gets registed by an OpenTelemetry Histogram instrument.
func (o *OTELSink) AddSampleWithLabels(key []string, val float32, labels []gometrics.Label) {
k := o.flattenKey(key, labels)
k := o.flattenKey(key)

o.mutex.Lock()
defer o.mutex.Unlock()
Expand All @@ -135,7 +135,7 @@ func (o *OTELSink) AddSampleWithLabels(key []string, val float32, labels []gomet

// IncrCounterWithLabels emits a Consul counter metric that gets registed by an OpenTelemetry Histogram instrument.
func (o *OTELSink) IncrCounterWithLabels(key []string, val float32, labels []gometrics.Label) {
k := o.flattenKey(key, labels)
k := o.flattenKey(key)

o.mutex.Lock()
defer o.mutex.Unlock()
Expand All @@ -160,7 +160,7 @@ func (o *OTELSink) IncrCounterWithLabels(key []string, val float32, labels []gom
func (o *OTELSink) EmitKey(key []string, val float32) {}

// flattenKey key along with its labels.
func (o *OTELSink) flattenKey(parts []string, labels []gometrics.Label) string {
func (o *OTELSink) flattenKey(parts []string) string {
buf := &bytes.Buffer{}
joined := strings.Join(parts, ".")

Expand Down
4 changes: 1 addition & 3 deletions lib/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ import (
)

func newCfg() (TelemetryConfig, error) {
// Manual reader outputs the aggregated metrics when reader.Collect is called.
reader := metric.NewManualReader()
opts := &hcptelemetry.OTELSinkOpts{
Logger: hclog.New(&hclog.LoggerOptions{Output: io.Discard}),
Reader: reader,
Reader: metric.NewManualReader(),
Ctx: context.Background(),
}

Expand Down

0 comments on commit fb8897d

Please sign in to comment.