client

package
v0.0.0-...-e20b040 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultEntityDurationTimeframeTo = DefaultEntityMinutesTimeframeTo * time.Minute
View Source
const DefaultEntityMinutesTimeframeFrom = DefaultEntityWeeksTimeframeFrom * 7 * 24 * 60
View Source
const DefaultEntityMinutesTimeframeTo = 0

Not extracting the last 10 minutes to make sure what we extract is stable And avoid extracting more entities than the TotalCount from the first page of extraction

View Source
const DefaultEntityWeeksTimeframeFrom = 7
View Source
const DefaultPageSizeEntitiesInt = 4000
View Source
const TypesAsEntitiesType = "TypesAsEntityList"

Variables

View Source
var DefaultPageSizeEntities = fmt.Sprintf("%d", DefaultPageSizeEntitiesInt)
View Source
var ErrSettingNotFound = errors.New("settings object not found")

ErrSettingNotFound is returned when no settings 2.0 object could be found

Functions

func GetDynamicFieldFromMapReflection

func GetDynamicFieldFromMapReflection(reflection reflect.Value, field string) reflect.Value

func GetDynamicFieldFromObject

func GetDynamicFieldFromObject(object interface{}, field string) reflect.Value

func GetDynatraceClassicURL

func GetDynatraceClassicURL(client *http.Client, environmentURL string) (string, error)

GetDynatraceClassicURL tries to fetch the URL of the classic environment using the API of a platform enabled environment

func GetDynatraceVersion

func GetDynatraceVersion(client *http.Client, environmentURL string) (version.Version, error)

GetDynatraceVersion returns the version of an environment

func GetStringFromMapReflection

func GetStringFromMapReflection(element reflect.Value, field string) string

func IsInvalidReflectionValue

func IsInvalidReflectionValue(value reflect.Value) bool

func L2FieldWithIdExists

func L2FieldWithIdExists(entitiesType EntitiesType, topField string, subField string) (reflect.Value, bool)

func NewOAuthClient

func NewOAuthClient(ctx context.Context, oauthConfig OauthCredentials) *http.Client

NewOAuthClient creates a new HTTP client that supports OAuth2 client credentials based authorization

func NewTokenAuthClient

func NewTokenAuthClient(token string) *http.Client

NewTokenAuthClient creates a new HTTP client that supports token based authorization

func WithAutoServerVersion

func WithAutoServerVersion() func(client *DynatraceClient)

WithAutoServerVersion can be used to let the client automatically determine the Dynatrace server version during creation using newDynatraceClient. If the server version is already known WithServerVersion should be used

func WithRetrySettings

func WithRetrySettings(retrySettings rest.RetrySettings) func(*DynatraceClient)

WithRetrySettings sets the retry settings to be used by the DynatraceClient

func WithServerVersion

func WithServerVersion(serverVersion version.Version) func(client *DynatraceClient)

WithServerVersion sets the Dynatrace version of the Dynatrace server/tenant the client will be interacting with

Types

type ApiVersionObject

type ApiVersionObject struct {
	Version string `json:"version"`
}

type Client

type Client interface {
	ConfigClient
	SettingsClient
	EntitiesClient
}

Client provides the functionality for performing basic CRUD operations on any Dynatrace API supported by monaco. It encapsulates the configuration-specific inconsistencies of certain APIs in one place to provide a common interface to work with. After all: A user of Client shouldn't care about the implementation details of each individual Dynatrace API. Its design is intentionally not dependent on the Config and Environment interfaces included in monaco. This makes sure, that Client can be used as a base for future tooling, which relies on a standardized way to access Dynatrace APIs.

func LimitClientParallelRequests

func LimitClientParallelRequests(client Client, maxParallelRequests int) Client

LimitClientParallelRequests utilizes the decorator pattern to limit parallel requests to the dynatrace API

type ConfigClient

type ConfigClient interface {
	// ListConfigs lists the available configs for an API.
	// It calls the underlying GET endpoint of the API. E.g. for alerting profiles this would be:
	//    GET <environment-url>/api/config/v1/alertingProfiles
	// The result is expressed using a list of Value (id and name tuples).
	ListConfigs(a api.API) (values []Value, err error)

	// ReadConfigById reads a Dynatrace config identified by id from the given API.
	// It calls the underlying GET endpoint for the API. E.g. for alerting profiles this would be:
	//    GET <environment-url>/api/config/v1/alertingProfiles/<id> ... to get the alerting profile
	ReadConfigById(a api.API, id string) (json []byte, err error)
	ReadConfigByIdSubId(a api.API, id string, subId string) (json []byte, err error)
}

ConfigClient is responsible for the classic Dynatrace configs. For settings objects, the SettingsClient is responsible. Each config endpoint is described by an [API] object to describe endpoints, structure, and behavior.

type ConstraintViolation

type ConstraintViolation struct {
	Path              string `json:"path"`
	Message           string `json:"message"`
	ParameterLocation string `json:"parameterLocation"`
	Location          string `json:"location"`
}

type DataEntry

type DataEntry struct {
	Name    string
	Id      string
	Owner   string
	Payload []byte
}

type DownloadSettingsObject

type DownloadSettingsObject struct {
	ExternalId    string          `json:"externalId"`
	SchemaVersion string          `json:"schemaVersion"`
	SchemaId      string          `json:"schemaId"`
	ObjectId      string          `json:"objectId"`
	Scope         string          `json:"scope"`
	Value         json.RawMessage `json:"value"`
}

DownloadSettingsObject is the response type for the ListSettings operation

type DummyClient

type DummyClient struct {
	Entries          map[api.API][]DataEntry
	Fs               afero.Fs
	RequestOutputDir string
}

func NewDummyClient

func NewDummyClient() *DummyClient

NewDummyClient creates a new DummyClient

func (*DummyClient) ConfigExistsByName

func (c *DummyClient) ConfigExistsByName(a api.API, name string) (exists bool, id string, err error)

func (*DummyClient) DeleteConfigById

func (c *DummyClient) DeleteConfigById(a api.API, id string) error

func (*DummyClient) DeleteSettings

func (l *DummyClient) DeleteSettings(_ string) error

func (*DummyClient) GetSettingById

func (c *DummyClient) GetSettingById(_ string) (*DownloadSettingsObject, error)

func (*DummyClient) ListConfigs

func (c *DummyClient) ListConfigs(a api.API) (values []Value, err error)

func (*DummyClient) ListEntities

func (*DummyClient) ListEntitiesTypes

func (c *DummyClient) ListEntitiesTypes() ([]EntitiesType, *EntitiesList, error)

func (*DummyClient) ListSchemas

func (c *DummyClient) ListSchemas() (SchemaList, error)

func (*DummyClient) ListSettings

func (*DummyClient) ListSettingsFlat

func (c *DummyClient) ListSettingsFlat(_ string, _ ListSettingsOptions) ([]string, error)

func (*DummyClient) ReadByName

func (c *DummyClient) ReadByName(a api.API, name string) ([]byte, error)

func (*DummyClient) ReadConfigById

func (c *DummyClient) ReadConfigById(a api.API, id string) ([]byte, error)

func (*DummyClient) ReadConfigByIdSubId

func (c *DummyClient) ReadConfigByIdSubId(a api.API, id string, subId string) ([]byte, error)

func (*DummyClient) UpsertConfigByName

func (c *DummyClient) UpsertConfigByName(a api.API, name string, data []byte) (entity DynatraceEntity, err error)

func (*DummyClient) UpsertConfigByNonUniqueNameAndId

func (c *DummyClient) UpsertConfigByNonUniqueNameAndId(a api.API, entityId string, name string, data []byte) (entity DynatraceEntity, err error)

type DynatraceClient

type DynatraceClient struct {
	// contains filtered or unexported fields
}

DynatraceClient is the default implementation of the HTTP client targeting the relevant Dynatrace APIs for Monaco

func NewClassicClient

func NewClassicClient(dtURL string, token string, opts ...func(dynatraceClient *DynatraceClient)) (*DynatraceClient, error)

NewClassicClient creates a new dynatrace client to be used for classic environments

func NewPlatformClient

func NewPlatformClient(dtURL string, token string, oauthCredentials OauthCredentials, opts ...func(dynatraceClient *DynatraceClient)) (*DynatraceClient, error)

NewPlatformClient creates a new dynatrace client to be used for platform enabled environments

func (*DynatraceClient) ListConfigs

func (d *DynatraceClient) ListConfigs(api api.API) (values []Value, err error)

func (*DynatraceClient) ListEntities

func (d *DynatraceClient) ListEntities(entitiesType EntitiesType, opts ListEntitiesOptions) (EntitiesList, error)

func (*DynatraceClient) ListEntitiesTypes

func (d *DynatraceClient) ListEntitiesTypes() ([]EntitiesType, *EntitiesList, error)

func (*DynatraceClient) ListSchemas

func (d *DynatraceClient) ListSchemas() (SchemaList, error)

func (*DynatraceClient) ListSettingsFlat

func (d *DynatraceClient) ListSettingsFlat(schemaId string, opts ListSettingsOptions) ([]string, error)

func (*DynatraceClient) ReadConfigById

func (d *DynatraceClient) ReadConfigById(api api.API, id string) (json []byte, err error)

func (*DynatraceClient) ReadConfigByIdSubId

func (d *DynatraceClient) ReadConfigByIdSubId(api api.API, id string, subId string) (json []byte, err error)

type DynatraceEntity

type DynatraceEntity struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

type EntitiesClient

type EntitiesClient interface {

	// ListEntitiesTypes returns all entities types
	ListEntitiesTypes() ([]EntitiesType, *EntitiesList, error)

	// ListEntities returns all entities objects for a given type.
	ListEntities(EntitiesType, ListEntitiesOptions) (EntitiesList, error)
}

type EntitiesList

type EntitiesList struct {
	From     string
	To       string
	Entities []string
}

type EntitiesType

type EntitiesType struct {
	EntitiesTypeId    string                   `json:"type"`
	ToRelationships   []map[string]interface{} `json:"toRelationships"`
	FromRelationships []map[string]interface{} `json:"fromRelationships"`
	Properties        []map[string]interface{} `json:"properties"`
}

func (EntitiesType) String

func (e EntitiesType) String() string

type EntitiesTypeListAsEntities

type EntitiesTypeListAsEntities struct {
	Entities []json.RawMessage `json:"types"`
}

type EntitiesTypeListResponse

type EntitiesTypeListResponse struct {
	Types []EntitiesType `json:"types"`
}

type EntityListResponseRaw

type EntityListResponseRaw struct {
	Entities []json.RawMessage `json:"entities"`
}

type ErrorResponse

type ErrorResponse struct {
	ErrorCode               int                   `json:"code"`
	Message                 string                `json:"message"`
	ConstraintViolationList []ConstraintViolation `json:"constraintViolations"`
}

type ErrorResponseStruct

type ErrorResponseStruct struct {
	ErrorResponse ErrorResponse `json:"error"`
}

type ListEntitiesOptions

type ListEntitiesOptions struct {
	TimeFromMinutes int
	TimeToMinutes   int
	EntityPageSize  int
}

type ListSettingsFilter

type ListSettingsFilter func(DownloadSettingsObject) bool

ListSettingsFilter can be used to filter fetched settings objects with custom criteria, e.g. o.ExternalId == ""

type ListSettingsOptions

type ListSettingsOptions struct {
	// DiscardValue specifies whether the value field of the returned
	// settings object shall be included in the payload
	DiscardValue bool
	// ListSettingsFilter can be set to pre-filter the result given a special logic
	Filter ListSettingsFilter
}

ListSettingsOptions are additional options for the ListSettings method of the Settings client

type OauthCredentials

type OauthCredentials struct {
	ClientID     string
	ClientSecret string
	TokenURL     string
	Scopes       []string
}

OauthCredentials holds information for authenticating to Dynatrace using Oauth2.0 client credential flow

type RespError

type RespError struct {
	Err        error
	StatusCode int
}

func (RespError) ConcurrentError

func (e RespError) ConcurrentError() string

func (RespError) Error

func (e RespError) Error() string

func (RespError) Unwrap

func (e RespError) Unwrap() error

type SchemaList

type SchemaList []struct {
	SchemaId string `json:"schemaId"`
}

type SchemaListResponse

type SchemaListResponse struct {
	Items      SchemaList `json:"items"`
	TotalCount int        `json:"totalCount"`
}

SchemaListResponse is the response type returned by the ListSchemas operation

type SettingsClient

type SettingsClient interface {

	// ListSchemas returns all schemas that the Dynatrace environment reports
	ListSchemas() (SchemaList, error)

	// ListSettings returns all settings objects for a given schema in a flat unformatted file.
	ListSettingsFlat(string, ListSettingsOptions) ([]string, error)
}

SettingsClient is the abstraction layer for CRUD operations on the Dynatrace Settings API. Its design is intentionally not dependent on Monaco objects.

This interface exclusively accesses the settings api of Dynatrace.

The base mechanism for all methods is the same: We identify objects to be updated/deleted by their external-id. If an object can not be found using its external-id, we assume that it does not exist. More documentation is written in each method's documentation.

type SettingsResponseRaw

type SettingsResponseRaw struct {
	Settings []map[string]interface{} `json:"items"`
}

type SyntheticEntity

type SyntheticEntity struct {
	EntityId string `json:"entityId"`
}

type SyntheticLocationResponse

type SyntheticLocationResponse struct {
	Locations []SyntheticValue `json:"locations"`
}

type SyntheticMonitorsResponse

type SyntheticMonitorsResponse struct {
	Monitors []SyntheticValue `json:"monitors"`
}

type SyntheticValue

type SyntheticValue struct {
	Name          string    `json:"name"`
	EntityId      string    `json:"entityId"`
	Type          string    `json:"type"`
	CloudPlatform *string   `json:"cloudPlatform"`
	Ips           *[]string `json:"ips"`
	Stage         *string   `json:"stage"`
	Enabled       *bool     `json:"enabled"`
}

type TokenAuthTransport

type TokenAuthTransport struct {
	http.RoundTripper
	// contains filtered or unexported fields
}

TokenAuthTransport should be used to enable a client to use dynatrace token authorization

func NewTokenAuthTransport

func NewTokenAuthTransport(baseTransport http.RoundTripper, token string) *TokenAuthTransport

NewTokenAuthTransport creates a new http transport to be used for token authorization

func (*TokenAuthTransport) RoundTrip

func (t *TokenAuthTransport) RoundTrip(req *http.Request) (*http.Response, error)

type Value

type Value struct {
	Id    string `json:"id"`
	Name  string `json:"name"`
	SubId string `json:"subID"`

	// Owner is used by dashboards to indicate the creator of the dashboard. We use it to filter Dynatrace created dashboards.
	Owner *string `json:"owner,omitempty"`

	// Type is used by synthetic-locations to indicate whether it is a PRIVATE location or not.
	Type *string `json:"type,omitempty"`
}

type ValuesResponse

type ValuesResponse struct {
	Values []Value `json:"values"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL