|
|
|
|
@ -11,17 +11,19 @@ |
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
package testutil |
|
|
|
|
package scrape |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"bytes" |
|
|
|
|
"encoding/binary" |
|
|
|
|
|
|
|
|
|
"github.com/gogo/protobuf/proto" |
|
|
|
|
// Intentionally using client model to simulate client in tests.
|
|
|
|
|
dto "github.com/prometheus/client_model/go" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// Write a MetricFamily into a protobuf
|
|
|
|
|
// Write a MetricFamily into a protobuf.
|
|
|
|
|
// This function is intended for testing scraping by providing protobuf serialized input.
|
|
|
|
|
func MetricFamilyToProtobuf(metricFamily *dto.MetricFamily) ([]byte, error) { |
|
|
|
|
buffer := &bytes.Buffer{} |
|
|
|
|
err := AddMetricFamilyToProtobuf(buffer, metricFamily) |
|
|
|
|
@ -31,7 +33,8 @@ func MetricFamilyToProtobuf(metricFamily *dto.MetricFamily) ([]byte, error) { |
|
|
|
|
return buffer.Bytes(), nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Append a MetricFamily protobuf representation to a buffer
|
|
|
|
|
// Append a MetricFamily protobuf representation to a buffer.
|
|
|
|
|
// This function is intended for testing scraping by providing protobuf serialized input.
|
|
|
|
|
func AddMetricFamilyToProtobuf(buffer *bytes.Buffer, metricFamily *dto.MetricFamily) error { |
|
|
|
|
protoBuf, err := proto.Marshal(metricFamily) |
|
|
|
|
if err != nil { |