Skip to content

Commit 3fd93b3

Browse files
bwplotkaaknuds1
authored andcommitted
semconv: Versioned Read feature.
Signed-off-by: bwplotka <[email protected]>
1 parent 4604607 commit 3fd93b3

File tree

15 files changed

+2554
-4
lines changed

15 files changed

+2554
-4
lines changed

cmd/prometheus/main.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import (
7171
"github.com/prometheus/prometheus/promql/parser"
7272
"github.com/prometheus/prometheus/rules"
7373
"github.com/prometheus/prometheus/scrape"
74+
"github.com/prometheus/prometheus/semconv"
7475
"github.com/prometheus/prometheus/storage"
7576
"github.com/prometheus/prometheus/storage/remote"
7677
"github.com/prometheus/prometheus/tracing"
@@ -217,6 +218,8 @@ type flagConfig struct {
217218
promqlEnableDelayedNameRemoval bool
218219

219220
promslogConfig promslog.Config
221+
222+
enableSemconvVersionedRead bool
220223
}
221224

222225
// setFeatureListOptions sets the corresponding options from the featureList.
@@ -297,6 +300,9 @@ func (c *flagConfig) setFeatureListOptions(logger *slog.Logger) error {
297300
case "use-uncached-io":
298301
c.tsdb.UseUncachedIO = true
299302
logger.Info("Experimental Uncached IO is enabled.")
303+
case "semconv-versioned-read":
304+
c.enableSemconvVersionedRead = true
305+
logger.Info("Experimental semconv versioned read enabled")
300306
default:
301307
logger.Warn("Unknown option for --enable-feature", "option", o)
302308
}
@@ -798,12 +804,17 @@ func main() {
798804
)
799805

800806
var (
801-
localStorage = &readyStorage{stats: tsdb.NewDBStats()}
802-
scraper = &readyScrapeManager{}
803-
remoteStorage = remote.NewStorage(logger.With("component", "remote"), prometheus.DefaultRegisterer, localStorage.StartTime, localStoragePath, time.Duration(cfg.RemoteFlushDeadline), scraper, cfg.scrape.EnableTypeAndUnitLabels)
804-
fanoutStorage = storage.NewFanout(logger, localStorage, remoteStorage)
807+
localStorage = &readyStorage{stats: tsdb.NewDBStats()}
808+
scraper = &readyScrapeManager{}
809+
remoteStorage = remote.NewStorage(logger.With("component", "remote"), prometheus.DefaultRegisterer, localStorage.StartTime, localStoragePath, time.Duration(cfg.RemoteFlushDeadline), scraper, cfg.scrape.EnableTypeAndUnitLabels)
810+
fanoutStorage = storage.NewFanout(logger, localStorage, remoteStorage)
811+
semconvReloader func(*config.Config) error
805812
)
806813

814+
if cfg.enableSemconvVersionedRead {
815+
fanoutStorage, semconvReloader = semconv.AwareStorage(fanoutStorage)
816+
}
817+
807818
var (
808819
ctxWeb, cancelWeb = context.WithCancel(context.Background())
809820
ctxRule = context.Background()
@@ -1014,6 +1025,14 @@ func main() {
10141025
}
10151026
return discoveryManagerNotify.ApplyConfig(c)
10161027
},
1028+
}, {
1029+
name: "semconv",
1030+
reloader: func(c *config.Config) error {
1031+
if !cfg.enableSemconvVersionedRead {
1032+
return nil
1033+
}
1034+
return semconvReloader(c)
1035+
},
10171036
}, {
10181037
name: "rules",
10191038
reloader: func(cfg *config.Config) error {

config/config.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,28 @@ type Config struct {
288288
RemoteWriteConfigs []*RemoteWriteConfig `yaml:"remote_write,omitempty"`
289289
RemoteReadConfigs []*RemoteReadConfig `yaml:"remote_read,omitempty"`
290290
OTLPConfig OTLPConfig `yaml:"otlp,omitempty"`
291+
SemConv SemConvConfig `yaml:"semconv,omitempty"`
291292

292293
loaded bool // Certain methods require configuration to use Load validation.
293294
}
294295

296+
// SemConvConfig represents semconv package runtime configuration.
297+
type SemConvConfig struct {
298+
// SchemaOverrides is a local mapping from the schema base URL (identifying schema
299+
// registries) to an alternative schema base URL. URLs are considered local
300+
// (within the process local filesystem) if they don't start with "http" prefix.
301+
//
302+
// This option is useful when manual adjustments to schema are needed or
303+
// for when reaching the Internet is not an option (local cache).
304+
//
305+
// For example, imagine data that uses a schema URL like https://bwplotka.dev/semconv/1.1.0.
306+
// Setting an override with "https://bwplotka.dev/semconv" -> "./semconv" will
307+
// cause Prometheus to look for the schema artifacts (e.g.in the current implementation
308+
// "./semconv/changelog.yaml" and "./semconv/ids.yaml" files) in the local
309+
// filesystem.
310+
SchemaOverrides map[string]string `yaml:"schema_overrides,omitempty"`
311+
}
312+
295313
// SetDirectory joins any relative file paths with dir.
296314
// This method writes to config, and it's not concurrency safe.
297315
func (c *Config) SetDirectory(dir string) {

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ require (
184184
github.com/knadh/koanf/v2 v2.3.0 // indirect
185185
github.com/kylelemons/godebug v1.1.0 // indirect
186186
github.com/mailru/easyjson v0.7.7 // indirect
187+
github.com/maruel/natural v1.1.1
187188
github.com/mattn/go-colorable v0.1.13 // indirect
188189
github.com/mattn/go-isatty v0.0.20 // indirect
189190
github.com/mdlayher/socket v0.4.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ github.com/linode/linodego v1.60.0 h1:SgsebJFRCi+lSmYy+C40wmKZeJllGGm+W12Qw4+yVd
342342
github.com/linode/linodego v1.60.0/go.mod h1:1+Bt0oTz5rBnDOJbGhccxn7LYVytXTIIfAy7QYmijDs=
343343
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
344344
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
345+
github.com/maruel/natural v1.1.1 h1:Hja7XhhmvEFhcByqDoHz9QZbkWey+COd9xWfCfn1ioo=
346+
github.com/maruel/natural v1.1.1/go.mod h1:v+Rfd79xlw1AgVBjbO0BEQmptqb5HvL/k9GRHB7ZKEg=
345347
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
346348
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
347349
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=

schema/labels.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
package schema
1515

1616
import (
17+
"strings"
18+
1719
"github.com/prometheus/common/model"
1820

1921
"github.com/prometheus/prometheus/model/labels"
@@ -134,6 +136,21 @@ func (m Metadata) NewIgnoreOverriddenMetadataLabelScratchBuilder(b *labels.Scrat
134136
return &IgnoreOverriddenMetadataLabelScratchBuilder{ScratchBuilder: b, overwrite: m}
135137
}
136138

139+
// String returns a string representation of the Metadata.
140+
func (m Metadata) String() string {
141+
var b strings.Builder
142+
b.WriteString(m.Name)
143+
if m.Unit != "" {
144+
b.WriteString("~")
145+
b.WriteString(m.Unit)
146+
}
147+
if m.Type != "" && m.Type != model.MetricTypeUnknown {
148+
b.WriteString(".")
149+
b.WriteString(string(m.Type))
150+
}
151+
return b.String()
152+
}
153+
137154
// IgnoreOverriddenMetadataLabelScratchBuilder is a wrapper over labels.ScratchBuilder
138155
// that ignores label additions that would collide with non-empty Overwrite Metadata fields.
139156
type IgnoreOverriddenMetadataLabelScratchBuilder struct {

0 commit comments

Comments
 (0)