Skip to content

Commit

Permalink
[receiver/mongodbatlas] do not expose method (open-telemetry#27032)
Browse files Browse the repository at this point in the history
Remove exposed function, only keep NewFactory to pass checkapi
  • Loading branch information
sakulali authored and jmsnll committed Nov 12, 2023
1 parent 506e292 commit 07da73a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 34 deletions.
27 changes: 27 additions & 0 deletions .chloggen/mongodbatlasreceiver-checkapi-26304.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: mongodbatlasreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Rename struct to pass checkapi.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [26304]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
1 change: 0 additions & 1 deletion cmd/checkapi/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ receiver/dockerstatsreceiver
receiver/jaegerreceiver
receiver/journaldreceiver
receiver/kafkareceiver
receiver/mongodbatlasreceiver
receiver/podmanreceiver
receiver/pulsarreceiver
receiver/windowseventlogreceiver
18 changes: 9 additions & 9 deletions receiver/mongodbatlasreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/exporter/exporterhelper"
rcvr "go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/scraperhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mongodbatlasreceiver/internal/metadata"
Expand All @@ -25,21 +25,21 @@ const (
)

// NewFactory creates a factory for MongoDB Atlas receiver
func NewFactory() rcvr.Factory {
return rcvr.NewFactory(
func NewFactory() receiver.Factory {
return receiver.NewFactory(
metadata.Type,
createDefaultConfig,
rcvr.WithMetrics(createMetricsReceiver, metadata.MetricsStability),
rcvr.WithLogs(createCombinedLogReceiver, metadata.LogsStability))
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability),
receiver.WithLogs(createCombinedLogReceiver, metadata.LogsStability))

}

func createMetricsReceiver(
_ context.Context,
params rcvr.CreateSettings,
params receiver.CreateSettings,
rConf component.Config,
consumer consumer.Metrics,
) (rcvr.Metrics, error) {
) (receiver.Metrics, error) {
cfg := rConf.(*Config)
recv := newMongoDBAtlasReceiver(params, cfg)
ms, err := newMongoDBAtlasScraper(recv)
Expand All @@ -52,10 +52,10 @@ func createMetricsReceiver(

func createCombinedLogReceiver(
_ context.Context,
params rcvr.CreateSettings,
params receiver.CreateSettings,
rConf component.Config,
consumer consumer.Logs,
) (rcvr.Logs, error) {
) (receiver.Logs, error) {
cfg := rConf.(*Config)

if !cfg.Alerts.Enabled && !cfg.Logs.Enabled && cfg.Events == nil {
Expand Down
18 changes: 9 additions & 9 deletions receiver/mongodbatlasreceiver/mongodb_event_to_logdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

func TestMongoeventToLogData4_4(t *testing.T) {
mongoevent := GetTestEvent4_4()
mongoevent := getTestEvent4_4()
pc := ProjectContext{
orgName: "Org",
Project: mongodbatlas.Project{Name: "Project"},
Expand Down Expand Up @@ -56,7 +56,7 @@ func TestMongoeventToLogData4_4(t *testing.T) {
}

func TestMongoeventToLogData4_2(t *testing.T) {
mongoevent := GetTestEvent4_2()
mongoevent := getTestEvent4_2()
pc := ProjectContext{
orgName: "Org",
Project: mongodbatlas.Project{Name: "Project"},
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestMongoeventToLogData4_2(t *testing.T) {
}

func TestUnknownSeverity(t *testing.T) {
mongoevent := GetTestEvent4_4()
mongoevent := getTestEvent4_4()
mongoevent.Severity = "Unknown"
pc := ProjectContext{
orgName: "Org",
Expand All @@ -108,7 +108,7 @@ func TestUnknownSeverity(t *testing.T) {
}

func TestMongoEventToAuditLogData5_0(t *testing.T) {
mongoevent := GetTestAuditEvent5_0()
mongoevent := getTestAuditEvent5_0()
pc := ProjectContext{
orgName: "Org",
Project: mongodbatlas.Project{Name: "Project"},
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestMongoEventToAuditLogData5_0(t *testing.T) {
}

func TestMongoEventToAuditLogData4_2(t *testing.T) {
mongoevent := GetTestAuditEvent4_2()
mongoevent := getTestAuditEvent4_2()
pc := ProjectContext{
orgName: "Org",
Project: mongodbatlas.Project{Name: "Project"},
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestMongoEventToAuditLogData4_2(t *testing.T) {
assert.Equal(t, "RAW MESSAGE", lr.Body().Str())
}

func GetTestEvent4_4() model.LogEntry {
func getTestEvent4_4() model.LogEntry {
return model.LogEntry{
Timestamp: model.LogTimestamp{
Date: "2022-09-12T18:10:27.215+00:00",
Expand All @@ -233,7 +233,7 @@ func GetTestEvent4_4() model.LogEntry {
}
}

func GetTestEvent4_2() model.LogEntry {
func getTestEvent4_2() model.LogEntry {
return model.LogEntry{
Severity: "I",
Component: "NETWORK",
Expand All @@ -246,7 +246,7 @@ func GetTestEvent4_2() model.LogEntry {
}
}

func GetTestAuditEvent5_0() model.AuditLog {
func getTestAuditEvent5_0() model.AuditLog {
return model.AuditLog{
Timestamp: model.LogTimestamp{
Date: "2022-09-16T15:26:52.563+00:00",
Expand Down Expand Up @@ -288,7 +288,7 @@ func GetTestAuditEvent5_0() model.AuditLog {
}
}

func GetTestAuditEvent4_2() model.AuditLog {
func getTestAuditEvent4_2() model.AuditLog {
return model.AuditLog{
Timestamp: model.LogTimestamp{
Date: "2022-09-16T15:26:52.563+0000",
Expand Down
26 changes: 13 additions & 13 deletions receiver/mongodbatlasreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (

"go.mongodb.org/atlas/mongodbatlas"
"go.opentelemetry.io/collector/pdata/pmetric"
rcvr "go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/scraperhelper"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mongodbatlasreceiver/internal"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mongodbatlasreceiver/internal/metadata"
)

type receiver struct {
type mongodbatlasreceiver struct {
log *zap.Logger
cfg *Config
client *internal.MongoDBAtlasClient
Expand All @@ -35,9 +35,9 @@ type timeconstraints struct {
resolution string
}

func newMongoDBAtlasReceiver(settings rcvr.CreateSettings, cfg *Config) *receiver {
func newMongoDBAtlasReceiver(settings receiver.CreateSettings, cfg *Config) *mongodbatlasreceiver {
client := internal.NewMongoDBAtlasClient(cfg.PublicKey, string(cfg.PrivateKey), cfg.RetrySettings, settings.Logger)
return &receiver{
return &mongodbatlasreceiver{
log: settings.Logger,
cfg: cfg,
client: client,
Expand All @@ -46,11 +46,11 @@ func newMongoDBAtlasReceiver(settings rcvr.CreateSettings, cfg *Config) *receive
}
}

func newMongoDBAtlasScraper(recv *receiver) (scraperhelper.Scraper, error) {
func newMongoDBAtlasScraper(recv *mongodbatlasreceiver) (scraperhelper.Scraper, error) {
return scraperhelper.NewScraper(metadata.Type, recv.scrape, scraperhelper.WithShutdown(recv.shutdown))
}

func (s *receiver) scrape(ctx context.Context) (pmetric.Metrics, error) {
func (s *mongodbatlasreceiver) scrape(ctx context.Context) (pmetric.Metrics, error) {
now := time.Now()
if err := s.poll(ctx, s.timeConstraints(now)); err != nil {
return pmetric.Metrics{}, err
Expand All @@ -59,7 +59,7 @@ func (s *receiver) scrape(ctx context.Context) (pmetric.Metrics, error) {
return s.mb.Emit(), nil
}

func (s *receiver) timeConstraints(now time.Time) timeconstraints {
func (s *mongodbatlasreceiver) timeConstraints(now time.Time) timeconstraints {
var start time.Time
if s.lastRun.IsZero() {
start = now.Add(s.cfg.CollectionInterval * -1)
Expand All @@ -73,11 +73,11 @@ func (s *receiver) timeConstraints(now time.Time) timeconstraints {
}
}

func (s *receiver) shutdown(context.Context) error {
func (s *mongodbatlasreceiver) shutdown(context.Context) error {
return s.client.Shutdown()
}

func (s *receiver) poll(ctx context.Context, time timeconstraints) error {
func (s *mongodbatlasreceiver) poll(ctx context.Context, time timeconstraints) error {
orgs, err := s.client.Organizations(ctx)
if err != nil {
return fmt.Errorf("error retrieving organizations: %w", err)
Expand Down Expand Up @@ -117,7 +117,7 @@ func (s *receiver) poll(ctx context.Context, time timeconstraints) error {
return nil
}

func (s *receiver) getNodeClusterNameMap(
func (s *mongodbatlasreceiver) getNodeClusterNameMap(
ctx context.Context,
projectID string,
) (map[string]string, error) {
Expand All @@ -140,7 +140,7 @@ func (s *receiver) getNodeClusterNameMap(
return clusterMap, nil
}

func (s *receiver) extractProcessMetrics(
func (s *mongodbatlasreceiver) extractProcessMetrics(
ctx context.Context,
time timeconstraints,
orgName string,
Expand Down Expand Up @@ -176,7 +176,7 @@ func (s *receiver) extractProcessMetrics(
return nil
}

func (s *receiver) extractProcessDatabaseMetrics(
func (s *mongodbatlasreceiver) extractProcessDatabaseMetrics(
ctx context.Context,
time timeconstraints,
orgName string,
Expand Down Expand Up @@ -224,7 +224,7 @@ func (s *receiver) extractProcessDatabaseMetrics(
return nil
}

func (s *receiver) extractProcessDiskMetrics(
func (s *mongodbatlasreceiver) extractProcessDiskMetrics(
ctx context.Context,
time timeconstraints,
orgName string,
Expand Down
4 changes: 2 additions & 2 deletions receiver/mongodbatlasreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestTimeConstraints(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)
// lastRun is nil
recv := receiver{
recv := mongodbatlasreceiver{
cfg: cfg,
}
now := time.Now()
Expand All @@ -55,7 +55,7 @@ func TestTimeConstraints(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)
now := time.Now()
recv := receiver{
recv := mongodbatlasreceiver{
cfg: cfg,
// set last run to 1 collection ago
lastRun: now.Add(cfg.CollectionInterval * -1),
Expand Down

0 comments on commit 07da73a

Please sign in to comment.