Skip to content

Commit

Permalink
Coralogix processor first PR (open-telemetry#33458)
Browse files Browse the repository at this point in the history
**Description:** <Describe what has changed.>
Adding a feature - Adding a feature to create templates (blueprints)
from sql queries.
Currently specifically for postgresql and mysql queries.

**Link to tracking Issue:** open-telemetry#33090

**Testing:** <Describe what testing was performed and which tests were
added.>
currently no tests, will be added in next PR

**Documentation:** <Describe the documentation added.>
Added documentation for possible configuration and the usecase of the
processor

---------

Co-authored-by: Curtis Robert <crobert@splunk.com>
Co-authored-by: Antoine Toulme <atoulme@splunk.com>
  • Loading branch information
3 people authored and f7o committed Sep 12, 2024
1 parent e3919d7 commit 89fe609
Show file tree
Hide file tree
Showing 20 changed files with 685 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .chloggen/coralogix-proccesor-first-pr.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: new_component

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: creating new component for coralogix features

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

# (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: []
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ pkg/winperfcounters/ @open-teleme

processor/attributesprocessor/ @open-telemetry/collector-contrib-approvers @boostchicken
processor/cumulativetodeltaprocessor/ @open-telemetry/collector-contrib-approvers @TylerHelmuth
processor/coralogixprocessor/ @open-telemetry/collector-contrib-approvers @galrose @crobert-1 @eyalatz @roycald245
processor/deltatocumulativeprocessor/ @open-telemetry/collector-contrib-approvers @sh0rez @RichieSams @jpkrohling
processor/deltatorateprocessor/ @open-telemetry/collector-contrib-approvers @Aneurysm9
processor/filterprocessor/ @open-telemetry/collector-contrib-approvers @TylerHelmuth @boostchicken
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ body:
- pkg/translator/zipkin
- pkg/winperfcounters
- processor/attributes
- processor/coralogix
- processor/cumulativetodelta
- processor/deltatocumulative
- processor/deltatorate
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ body:
- pkg/translator/zipkin
- pkg/winperfcounters
- processor/attributes
- processor/coralogix
- processor/cumulativetodelta
- processor/deltatocumulative
- processor/deltatorate
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ body:
- pkg/translator/zipkin
- pkg/winperfcounters
- processor/attributes
- processor/coralogix
- processor/cumulativetodelta
- processor/deltatocumulative
- processor/deltatorate
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/unmaintained.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ body:
- pkg/translator/zipkin
- pkg/winperfcounters
- processor/attributes
- processor/coralogix
- processor/cumulativetodelta
- processor/deltatocumulative
- processor/deltatorate
Expand Down
1 change: 1 addition & 0 deletions cmd/githubgen/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rlankfo
swar8080
zpzhuSplunk
thmshmm
galrose
cemdk
tomasmota
m1rp
Expand Down
1 change: 1 addition & 0 deletions processor/coralogixprocessor/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
88 changes: 88 additions & 0 deletions processor/coralogixprocessor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Coralogix Processor

<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [development]: traces |
| Distributions | [] |
| Warnings | [Statefulness](#warnings) |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aprocessor%2Fcoralogix%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aprocessor%2Fcoralogix) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aprocessor%2Fcoralogix%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aprocessor%2Fcoralogix) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@crobert-1](https://www.github.com/crobert-1), [@galrose](https://www.github.com/galrose), [@eyalatz](https://www.github.com/eyalatz), [@roycald245](https://www.github.com/roycald245) |

[development]: https://github.com/open-telemetry/opentelemetry-collector#development
<!-- end autogenerated section -->

## Description

The Coralogix processor adds attributes to spans that enable features in Coralogix.

## Features

### DB Statement Blueprints

This feature enables the processor to create blueprints from SQL queries, this means replacing any variables with `?`.
The blueprint is also hashed to be able to be used with the spanmetrics connector.
Long queries can be an issue when being stored in certain metric stores.
Blueprints alleviate this problem by using the hash as the identifying dimension on the metric, which enables
users to query metrics by blueprints.

The added attributes are `db.statement.blueprint` and `db.statement.blueprint.id`.

* `db.statement.blueprint` contains the blueprinted version of the statement, we require them to be sent to Coralogix to
display your blueprinted statement
* `db.statement.blueprint.id` contains a hash of the statement, this way we can add it as a dimension in the spanmetrics
connector and use it to query your blueprints.
* `sampling.priority` if enabled contains the value 100 for new blueprints, further explanation below.

#### Sampling

If sampling is enabled then it stores the found blueprints in an in-memory cache to be able to send only new blueprints
that haven't been seen yet.
This only adds an attribute to the span named `sampling.priority`, if the blueprint is new then the sampling priority
will be `100`.

Using this key it's possible to use either
the [Tail Sampler](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/tailsamplingprocessor)
or
the [Probabilistic Sampler](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/probabilisticsamplerprocessor)
to only send new blueprints to Coralogix.
If sampling is not enabled it won't cache anything and the `sampling.priority` attribute won't be added.

The cache is limited by the `max_cache_size_mib` configuration, if the cache is full it will remove the oldest entries
to make space for new ones.
The cache stores hashes of the queries, each hash is 8 bytes, so the number of maximum cache entries is calculated
by `max_cache_size_mib * 1024 * 1024 / 8`.

## Config

* `db_statement_blueprints`
* `sampling`:
* `enabled`: (default: `false`) If enabled, adds the attribute `sampling.priority` with a value of `100` to spans with new
blueprints.
Refer to the [Sampling section](#sampling) for more information.
* `max_cache_size_mib` (default: `1024`) The size of the cache in mebibytes to store seen blueprints hashes.

### Basic Setup

This setup is without sampling meaning no `sampling.priority` attribute will be added to spans.
The cache will be disabled.

```yaml
processors:
coralogix:
db_statement_blueprints:
```
### With Sampling Config
This setup will enable the cache to store seen blueprints and add the `sampling.priority` attribute to spans with new
blueprints.

```yaml
processors:
coralogix:
db_statement_blueprints:
sampling:
enabled: true
max_cache_size_mib: 1024 #1GiB
```
29 changes: 29 additions & 0 deletions processor/coralogixprocessor/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package coralogixprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/coralogixprocessor"

import "fmt"

type samplingConfig struct {
enabled bool `mapstructure:"enabled"`
maxCacheSizeMib int64 `mapstructure:"max_cache_size_mib"`
}

type databaseBlueprintsConfig struct {
sampling samplingConfig `mapstructure:"sampling"`
}

type Config struct {
databaseBlueprintsConfig `mapstructure:"database_blueprints_config"`
}

func (c *Config) Validate() error {
if c.databaseBlueprintsConfig.sampling.enabled && c.databaseBlueprintsConfig.sampling.maxCacheSizeMib <= 0 {
return fmt.Errorf("max_cache_size_mib must be a positive integer")
}
if c.databaseBlueprintsConfig.sampling.enabled && c.databaseBlueprintsConfig.sampling.maxCacheSizeMib != 0 {
return fmt.Errorf("max_cache_size_mib can only be defined when sampling is enabled")
}
return nil
}
6 changes: 6 additions & 0 deletions processor/coralogixprocessor/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:generate mdatagen metadata.yaml

package coralogixprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/coralogixprocessor"
45 changes: 45 additions & 0 deletions processor/coralogixprocessor/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package coralogixprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/coralogixprocessor"

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/processor"

"github.com/open-telemetry/opentelemetry-collector-contrib/processor/coralogixprocessor/internal/metadata"
)

// NewFactory returns a new factory for the Span processor.
func NewFactory() processor.Factory {
return processor.NewFactory(
metadata.Type,
createDefaultConfig,
processor.WithTraces(createTracesProcessor, component.StabilityLevelDevelopment))
}

func createDefaultConfig() component.Config {
return &Config{}
}

func createTracesProcessor(
ctx context.Context,
params processor.Settings,
baseCfg component.Config,
nextConsumer consumer.Traces,
) (processor.Traces, error) {
coralogixCfg := baseCfg.(*Config)

coralogixProcessor, err := newCoralogixProcessor(ctx,
params,
coralogixCfg,
nextConsumer)
if err != nil {
return nil, err
}

return coralogixProcessor, nil
}
135 changes: 135 additions & 0 deletions processor/coralogixprocessor/generated_component_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 89fe609

Please sign in to comment.