Skip to content

Commit

Permalink
Add configsource component (#2720)
Browse files Browse the repository at this point in the history
* Add configsource component

Create the new component with  minimal code addition.

* Add ApplyConfigSources to a configuration

* Add ApplyConfigSources to a configuration

* Add ConfigSourceSettings

* Add local expandEnvConfig to configsource package

Avoids exposing it from config package.

* Relocate configsource to config/interal

* Move ConfigSource from component package to under configsource

* Fixes after files moved

* Make configmodels.ConfigSource internal

* Add comments and some renames

* Fix deepestConfigSourcesFirst

Fix whitespace

* Fix whitespace

* Do not allow nested config source invocations

* Undo accidental change to go.sum

* PR Feedback

* Reducing scope: keeping only config source interfaces

* Remove boiler plate code that can be added later

* Reduce the interface to a minimum

* Return error from Session.Close
  • Loading branch information
pjanotti authored Mar 23, 2021
1 parent 38dc164 commit c31e762
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions config/internal/configsource/component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright The OpenTelemetry Authors
//
// 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
//
// http://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.

package configsource

import (
"context"
)

// ConfigSource is the interface to be implemented by objects used by the collector
// to retrieve external configuration information.
type ConfigSource interface {
// NewSession must create a Session object that will be used to inject data into
// a configuration.
//
// The Session object should use its creation according to their ConfigSource needs:
// lock resources, suspend background tasks, etc. An implementation, for instance,
// can use the creation of the Session object to prevent torn configurations,
// by acquiring a lock (or some other mechanism) that prevents concurrent changes to the
// configuration during the middle of a session.
//
// The code managing the returned Session object must guarantee that the object is not used
// concurrently.
NewSession(ctx context.Context) (Session, error)
}

// Session is the interface used to inject configuration data from a ConfigSource. A Session
// object is created from a ConfigSource. The code using Session objects must guarantee that
// methods of a single instance are not called concurrently.
type Session interface {
// Apply goes to the configuration source, and according to the specified selector and
// parameters retrieves a configuration value that is injected into the configuration.
//
// The selector is a string that is required on all invocations, the params are optional.
Apply(ctx context.Context, selector string, params interface{}) (interface{}, error)

// Close signals that the object won't be used anymore to inject data into a configuration.
// Each Session object should use this call according to their needs: release resources,
// close communication channels, etc.
Close(ctx context.Context) error
}

0 comments on commit c31e762

Please sign in to comment.