-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Utilize resources This commit makes a series of changes to make use of the new top-level resource field. The contents of `$resource` use the same resource standard as Open Telemetry. See here for details: https://github.com/open-telemetry/opentelemetry-specification/tree/master/specification/resource/semantic_conventions This adds support for accessing fields with dots in them using syntax like `$record['field.with.dots']`. This also modifies the `host_metadata`, `k8s_event_input`, and `k8s_metadata_decorator` operators to add resource identifiers to the entry. Additionally, it adds support in the `google_cloud_output` for using the resource field to add logs to a monitored resource. In the process, it moves `google_cloud_output` into its own package for better organization of its multiple files. Includes a fix for a minor issue where rendering plugin ID in the template would set it as <no value> if using a default plugin ID. Includes a fix for an issue where not all k8s events had a LastTimestamp, so now we prefer EventTimestamp, but fall back to LastTimestamp, then FirstTimestamp
- Loading branch information
1 parent
949959c
commit e614037
Showing
22 changed files
with
929 additions
and
257 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
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
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
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,57 @@ | ||
package entry | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// ResourceField is the path to an entry's resource key | ||
type ResourceField struct { | ||
key string | ||
} | ||
|
||
// Get will return the resource value and a boolean indicating if it exists | ||
func (r ResourceField) Get(entry *Entry) (interface{}, bool) { | ||
if entry.Resource == nil { | ||
return "", false | ||
} | ||
val, ok := entry.Resource[r.key] | ||
return val, ok | ||
} | ||
|
||
// Set will set the resource value on an entry | ||
func (r ResourceField) Set(entry *Entry, val interface{}) error { | ||
if entry.Resource == nil { | ||
entry.Resource = make(map[string]string, 1) | ||
} | ||
|
||
str, ok := val.(string) | ||
if !ok { | ||
return fmt.Errorf("cannot set a resource to a non-string value") | ||
} | ||
entry.Resource[r.key] = str | ||
return nil | ||
} | ||
|
||
// Delete will delete a resource key from an entry | ||
func (r ResourceField) Delete(entry *Entry) (interface{}, bool) { | ||
if entry.Resource == nil { | ||
return "", false | ||
} | ||
|
||
val, ok := entry.Resource[r.key] | ||
delete(entry.Resource, r.key) | ||
return val, ok | ||
} | ||
|
||
func (r ResourceField) String() string { | ||
if strings.Contains(r.key, ".") { | ||
return fmt.Sprintf(`$resource['%s']`, r.key) | ||
} | ||
return "$resource." + r.key | ||
} | ||
|
||
// NewResourceField will creat a new resource field from a key | ||
func NewResourceField(key string) Field { | ||
return Field{ResourceField{key}} | ||
} |
Oops, something went wrong.