Skip to content

Commit 7c728ef

Browse files
authored
receiver/prometheus: start implementation. (#267)
1 parent 8ea43dd commit 7c728ef

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

receiver/prometheus/doc.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2018, OpenCensus Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package prometheus has the logic for scraping Prometheus metrics from
16+
// already instrumented applications and then passing them onto a metricsink instance.
17+
package prometheus
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2018, OpenCensus Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package prometheus
16+
17+
import (
18+
"errors"
19+
"time"
20+
21+
"github.com/census-instrumentation/opencensus-service/receiver"
22+
)
23+
24+
// Receiver is the type used to handle metrics from OpenCensus exporters.
25+
type Receiver struct {
26+
metricSink receiver.MetricsReceiverSink
27+
metricBufferPeriod time.Duration
28+
metricBufferCount int
29+
}
30+
31+
// New creates a new prometheus.Receiver reference.
32+
func New(ms receiver.MetricsReceiverSink, opts ...Option) (*Receiver, error) {
33+
if ms == nil {
34+
return nil, errors.New("needs a non-nil receiver.MetricsReceiverSink")
35+
}
36+
pr := &Receiver{metricSink: ms}
37+
for _, opt := range opts {
38+
opt.WithReceiver(pr)
39+
}
40+
return pr, nil
41+
}
42+
43+
const receiverName = "prometheus"
44+
45+
// Export is the gRPC method that exports streamed metrics from
46+
// OpenCensus-metricproto compatible libraries/applications to MetricSink.
47+
func (pr *Receiver) Export() error {
48+
// TODO: scrape metrics from Prometheus endpoint and convert to OC metrics.
49+
return nil
50+
}

receiver/prometheus/options.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2018, OpenCensus Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package prometheus
16+
17+
import "time"
18+
19+
// Option interface defines for configuration settings to be applied to receivers.
20+
//
21+
// WithReceiver applies the configuration to the given receiver.
22+
type Option interface {
23+
WithReceiver(*Receiver)
24+
}
25+
26+
type metricBufferPeriod struct {
27+
period time.Duration
28+
}
29+
30+
var _ Option = (*metricBufferPeriod)(nil)
31+
32+
func (mfd *metricBufferPeriod) WithReceiver(ocr *Receiver) {
33+
ocr.metricBufferPeriod = mfd.period
34+
}
35+
36+
// WithMetricBufferPeriod is an option that allows one to configure
37+
// the period that spans are buffered for before the Receiver
38+
// sends them to its MetricsReceiver.
39+
func WithMetricBufferPeriod(period time.Duration) Option {
40+
return &metricBufferPeriod{period: period}
41+
}
42+
43+
type metricBufferCount int
44+
45+
var _ Option = (*metricBufferCount)(nil)
46+
47+
func (mpc metricBufferCount) WithReceiver(oci *Receiver) {
48+
oci.metricBufferCount = int(mpc)
49+
}
50+
51+
// WithMetricBufferCount is an option that allows one to configure
52+
// the number of metrics that are buffered before the Receiver
53+
// send them to its MetricsReceiverSink.
54+
func WithMetricBufferCount(count int) Option {
55+
return metricBufferCount(count)
56+
}

0 commit comments

Comments
 (0)