mirror of
https://git.mirrors.martin98.com/https://github.com/ceph/ceph-csi.git
synced 2025-08-20 09:59:05 +08:00
Several packages are only used while running the e2e suite. These packages are less important to update, as the they can not influence the final executable that is part of the Ceph-CSI container-image. By moving these dependencies out of the main Ceph-CSI go.mod, it is easier to identify if a reported CVE affects Ceph-CSI, or only the testing (like most of the Kubernetes CVEs). Signed-off-by: Niels de Vos <ndevos@ibm.com>
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package telemetry
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
// Resource information.
|
|
type Resource struct {
|
|
// Attrs are the set of attributes that describe the resource. Attribute
|
|
// keys MUST be unique (it is not allowed to have more than one attribute
|
|
// with the same key).
|
|
Attrs []Attr `json:"attributes,omitempty"`
|
|
// DroppedAttrs is the number of dropped attributes. If the value
|
|
// is 0, then no attributes were dropped.
|
|
DroppedAttrs uint32 `json:"droppedAttributesCount,omitempty"`
|
|
}
|
|
|
|
// UnmarshalJSON decodes the OTLP formatted JSON contained in data into r.
|
|
func (r *Resource) UnmarshalJSON(data []byte) error {
|
|
decoder := json.NewDecoder(bytes.NewReader(data))
|
|
|
|
t, err := decoder.Token()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if t != json.Delim('{') {
|
|
return errors.New("invalid Resource type")
|
|
}
|
|
|
|
for decoder.More() {
|
|
keyIface, err := decoder.Token()
|
|
if err != nil {
|
|
if errors.Is(err, io.EOF) {
|
|
// Empty.
|
|
return nil
|
|
}
|
|
return err
|
|
}
|
|
|
|
key, ok := keyIface.(string)
|
|
if !ok {
|
|
return fmt.Errorf("invalid Resource field: %#v", keyIface)
|
|
}
|
|
|
|
switch key {
|
|
case "attributes":
|
|
err = decoder.Decode(&r.Attrs)
|
|
case "droppedAttributesCount", "dropped_attributes_count":
|
|
err = decoder.Decode(&r.DroppedAttrs)
|
|
default:
|
|
// Skip unknown.
|
|
}
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|