How do you define a `google.protobuf.Timestamp` s...
# protobufs
r
How do you define a
google.protobuf.Timestamp
struct in grpcInteraction, which is
Copy code
/ In JSON format, the Timestamp type is encoded as a string in the
// [RFC 3339](<https://www.ietf.org/rfc/rfc3339.txt>) format. That is, the
// format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
// where {year} is always expressed using four digits while {month}, {day},
// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
// is required. A proto3 JSON serializer should always use UTC (as indicated by
// "Z") when printing the Timestamp type and a proto3 JSON parser should be
// able to accept both UTC and other timezones (as indicated by an offset).
//
// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
// 01:30 UTC on January 15, 2017.
//
// In JavaScript, one can convert a Date object to this format using the
// standard
// [toISOString()](<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString>)
// method. In Python, a standard `datetime.datetime` object can be converted
// to this format using
// [`strftime`](<https://docs.python.org/2/library/time.html#time.strftime>) with
// the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
// the Joda Time's [`ISODateTimeFormat.dateTime()`](
// <http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D>
// ) to obtain a formatter capable of generating timestamps in this format.
//
//
message Timestamp {
  // Represents seconds of UTC time since Unix epoch
  // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
  // 9999-12-31T23:59:59Z inclusive.
  int64 seconds = 1;

  // Non-negative fractions of a second at nanosecond resolution. Negative
  // second values with fractions must still have non-negative nanos values
  // that count forward in time. Must be from 0 to 999,999,999
  // inclusive.
  int32 nanos = 2;
}
This approach does not work
Copy code
grpcInteraction := `{
		"pact:proto": "` + path1 + `",
		"pact:proto-service": "Service/Method",
		"pact:content-type": "application/protobuf",
		"request": {
		"id": "matching(type, '00000000-0000-0000-0000-000000000001')"
		},
		"response": {
			"id": "matching(type, '00000000-0000-0000-0000-000000000001')",
			"card_manufacture_last_send" : {
				"seconds":"matching(number, 1)",
				"nanos":"matching(number, 1)"
			}
		}
	}`
This too, does not work
Copy code
grpcInteraction := `{
		"pact:proto": "` + path1 + `",
		"pact:proto-service": "Service/Method",
		"pact:content-type": "application/protobuf",
		"request": {
		"id": "matching(type, '00000000-0000-0000-0000-000000000001')"
		},
		"response": {
			"id": "matching(type, '00000000-0000-0000-0000-000000000001')",
			"card_manufacture_last_send": "matching(type,'2022-08-10T20:25:04.835478326Z')"
		}
	}`
The rest of nested fields work.
message is defined like that:
Copy code
message GetCardConfigManufacturerResponse {
  string id = 1;
  google.protobuf.Timestamp card_manufacture_last_send = 2;
}
u
Timestamp is just a message, there is nothing special about it. What doesn't work?
r
It' very hard to tell cause I don't get any error feedback. The test just fails. It goes throught buy the response is empty.
Without this field. Field is ommited in grpcIinteraction.
When I add it
The resp is empty
u
Maybe try a number bigger than 1. Current epoc timestamp is 1660204683. Also, set the nanos to 0, you don't need that precision.
r
Same error with 😕
Look how the pact differs: Fail:
Pass:
Can you point where in pact-protobuf-plugin source code should I set log print so I can debugg it. Some functions?
u
You can also enable trace logs.
They will be very verbose, but will have lots of info
r
This?
I have this set but see no difference in test output.
message has been deleted
u
It will log to a file in the plugin directory
as well as to the test output
Maybe the log level is not being set properly
r
Test still logs ojlt DEBUG
message has been deleted
u
I'll need to chat to @Matt (pactflow.io / pact-js / pact-go) because the log level is not being passed through to the plugin
👋 2
r
in logs the field exist
m
Interesting. I thought the plugin logs went to a separate log file? How do I get them into the main one?
u
They go to both, but they are staying as DEBUG so the trace level is not being passed through
m
Ok cool. I think the issue is that setloglevel needs to panic if used like the above. As you know, the log level can't be changed after the runtime is established
I have some ideas for that.
When I'm back at my desk Robert I'll show you how to address that. I think it's just a matter of setting the log level before creating the NewSyncPact...
r
And thanks for your help guys.
👍 2
When I set it before NewSyncPact. and it switches between DEBUG and INFO. But TRACE has no impacto on logs in terminal.
m
🤔
r
FYI When I run the tests like
Copy code
LOG_LEVEL=debug go test ./...
It does show the debugging informaton. I wonder if there can be some conflict between
logrus
and
hashicorp/logutils
and this variable
LOG_LEVEL
sets it for both of them.
m
LOG_LEVEL
is a pretty standard environment variable. Are you suggesting we default to a different one for Pact to avoid conflict with logrus?