forked from open-telemetry/opentelemetry-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce "split" metric schema transformation
This is a new transformation type that allows to describe a change where a metric is converted to several other metrics by eliminating an attribute. An example of such change that happened recently is this: open-telemetry/opentelemetry-specification#2617 This PR implements specification change open-telemetry/opentelemetry-specification#2653 This PR creates package v1.1 for the new functionality. The old package v1.0 remains unchanged.
- Loading branch information
1 parent
eb9e058
commit c64f9c0
Showing
12 changed files
with
703 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/Masterminds/semver/v3" | ||
) | ||
|
||
// CheckFileFormatField validates the file format field according to the rules here: | ||
// https://github.com/open-telemetry/oteps/blob/main/text/0152-telemetry-schemas.md#schema-file-format-number | ||
func CheckFileFormatField(fileFormat string, supportedFormatMajor, supportedFormatMinor int) error { | ||
// Verify that the version number in the file is a semver. | ||
fileFormatParsed, err := semver.StrictNewVersion(fileFormat) | ||
if err != nil { | ||
return fmt.Errorf( | ||
"invalid schema file format version number %q (expected semver): %w", | ||
fileFormat, err, | ||
) | ||
} | ||
|
||
// Check that the major version number in the file is the same as what we expect. | ||
if fileFormatParsed.Major() != uint64(supportedFormatMajor) { | ||
return fmt.Errorf( | ||
"this library cannot parse file formats with major version other than %v", | ||
supportedFormatMajor, | ||
) | ||
} | ||
|
||
// Check that the file minor version number is not greater than | ||
// what is requested supports. | ||
if fileFormatParsed.Minor() > uint64(supportedFormatMinor) { | ||
supportedFormatMajorMinor := strconv.Itoa(supportedFormatMajor) + "." + | ||
strconv.Itoa(supportedFormatMinor) // 1.0 | ||
|
||
return fmt.Errorf( | ||
"unsupported schema file format minor version number, expected no newer than %v, got %v", | ||
supportedFormatMajorMinor+".x", fileFormat, | ||
) | ||
} | ||
|
||
// Patch, prerelease and metadata version number does not matter, so we don't check it. | ||
|
||
return nil | ||
} | ||
|
||
func CheckSchemaURL(schemaURL string) error { | ||
if strings.TrimSpace(schemaURL) == "" { | ||
return fmt.Errorf("schema_url field is missing") | ||
} | ||
|
||
if _, err := url.Parse(schemaURL); err != nil { | ||
return fmt.Errorf("invalid URL specified in schema_url field: %w", err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.