-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial structure for new pdata metrics exporter
- Loading branch information
Showing
5 changed files
with
86 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// 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 | ||
// | ||
// https://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. | ||
|
||
// This file contains the rewritten googlecloud metrics exporter which no longer takes | ||
// dependency on the OpenCensus stackdriver exporter. | ||
|
||
package collector | ||
|
||
import ( | ||
"context" | ||
|
||
monitoring "cloud.google.com/go/monitoring/apiv3/v2" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/exporter/exporterhelper" | ||
"go.opentelemetry.io/collector/model/pdata" | ||
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3" | ||
) | ||
|
||
// metricsExporter is the GCM exporter that uses pdata directly | ||
type metricsExporter struct { | ||
cfg *Config | ||
client *monitoring.MetricClient | ||
} | ||
|
||
func (me *metricsExporter) Shutdown(context.Context) error { | ||
return me.client.Close() | ||
} | ||
|
||
func newGoogleCloudMetricsExporter( | ||
ctx context.Context, | ||
cfg *Config, | ||
set component.ExporterCreateSettings, | ||
) (component.MetricsExporter, error) { | ||
setVersionInUserAgent(cfg, set.BuildInfo.Version) | ||
|
||
client, err := monitoring.NewMetricClient(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
mExp := &metricsExporter{ | ||
cfg: cfg, | ||
client: client, | ||
} | ||
|
||
return exporterhelper.NewMetricsExporter( | ||
cfg, | ||
set, | ||
mExp.pushMetrics, | ||
exporterhelper.WithShutdown(mExp.Shutdown), | ||
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: defaultTimeout}), | ||
exporterhelper.WithQueue(cfg.QueueSettings), | ||
exporterhelper.WithRetry(cfg.RetrySettings)) | ||
} | ||
|
||
// pushMetrics calls pushes pdata metrics to GCM, creating metric descriptors if necessary | ||
func (me *metricsExporter) pushMetrics(ctx context.Context, m pdata.Metrics) error { | ||
// TODO: self observability | ||
points := numPoints(nil) | ||
dropped := 0 | ||
var err error = nil | ||
recordPointCount(ctx, points-dropped, dropped, err) | ||
return nil | ||
} | ||
|
||
func numPoints(req []*monitoringpb.CreateTimeSeriesRequest) int { | ||
// TODO | ||
return 0 | ||
} |