damondouglas commented on code in PR #25610:
URL: https://github.com/apache/beam/pull/25610#discussion_r1128645798


##########
learning/tour-of-beam/backend/README.md:
##########
@@ -39,6 +39,7 @@ To re-generate:
 $ go generate -x ./...
 ```
 
+> Note: this requires [`protoc`](https://grpc.io/docs/protoc-installation/) 
version `>= 3.15` and [`moq`](https://github.com/matryer/moq) tools to be 
installed

Review Comment:
   Does this generate the proto stubs?  I think we should either use buf which 
is already used for the Beam Playground here.  Or convert the Beam Playground 
to this.  Either way, both should be the same.



##########
playground/api/v1/api.proto:
##########
@@ -314,6 +314,17 @@ message GetSnippetResponse {
   Complexity complexity = 4;
 }
 
+// GetMetadataRequest represents request for runner metadata
+message GetMetadataRequest {}
+
+// GetMetadataResponse contains metadata about the runner
+message GetMetadataResponse {
+  string runner_sdk = 1;
+  optional string build_commit_hash = 2;
+  optional int64 build_commit_timestamp_seconds_since_epoch = 3;
+  optional string beam_sdk_version = 4;

Review Comment:
   > Beginning in protobuf v3.14, primitive fields can distinguish between the 
default value and unset value by using the [optional 
keyword](https://cloud.google.com/apis/design/design_patterns.md#optional_primitive_fields),
 although this is generally discouraged.
   
   See: https://cloud.google.com/apis/design/proto3



##########
playground/backend/cmd/server/controller.go:
##########
@@ -529,3 +529,31 @@ func (controller *playgroundController) GetSnippet(ctx 
context.Context, info *pb
        }
        return &response, nil
 }
+
+// GetMetadata returns runner metadata
+func (controller *playgroundController) GetMetadata(_ context.Context, _ 
*pb.GetMetadataRequest) (*pb.GetMetadataResponse, error) {
+       commitTimestampInteger := func() *int64 {
+               timestamp, err := strconv.ParseInt(BuildCommitTimestamp, 10, 64)
+               if err != nil {
+                       logger.Errorf("GetMetadata(): failed to parse 
BuildCommitTimestamp (\"%s\"): %s", BuildCommitTimestamp, err.Error())
+                       return nil
+               }
+               return &timestamp
+       }()
+
+       buildCommitHash := func() *string {
+               if BuildCommitHash == "" {
+                       return nil
+               }
+               return &BuildCommitHash
+       }()

Review Comment:
   This unreadable code block is due to the use of the optional keyword 
[here](https://github.com/akvelon/beam/blob/get-metadata-endpoint-playground/playground/api/v1/api.proto#L323)
 [which is discouraged](https://cloud.google.com/apis/design/proto3). The 
optional keyword leads to a string* instead of just a string.



##########
playground/backend/containers/git-functions.gradle:
##########
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * License); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ext.getGitCommitHash = () -> {
+   def stdout = new ByteArrayOutputStream()
+   exec {
+      executable('git')
+      args('rev-parse', 'HEAD')
+      standardOutput = stdout
+   }
+   return stdout.toString().trim()
+} as Closure<String>
+
+ext.getGitCommitTimestamp = () -> {
+   def stdout = new ByteArrayOutputStream()
+   exec {
+      executable('git')
+      args('show', '-s', '--format=%ct', 'HEAD')
+      standardOutput = stdout
+   }
+   return stdout.toString().trim()
+} as Closure<String>

Review Comment:
   Why is a gradle wrapper needed? Why not just run the command in the context 
where the value is needed?



##########
playground/backend/containers/go/build.gradle:
##########
@@ -83,19 +84,22 @@ task copyDockerfileDependencies(type: Copy) {
 }
 
 docker {
-  name containerImageName(
-          name: project.docker_image_default_repo_prefix + 
"playground-backend-go",
-          root: project.rootProject.hasProperty(["docker-repository-root"]) ?
-                  project.rootProject["docker-repository-root"] :
-                  project.docker_image_default_repo_root)
-  files "./build/"
-  tags containerImageTags()
-  buildArgs(['BASE_IMAGE': project.rootProject.hasProperty(["base-image"]) ?
-                           project.rootProject["base-image"] :
-                           "golang:1.18-bullseye",
-             'SDK_TAG': project.rootProject.hasProperty(["sdk-tag"]) ?
-                  project.rootProject["sdk-tag"] : 
project.rootProject.sdk_version,
-             'SDK_TAG_LOCAL': project.rootProject.sdk_version])
+   name containerImageName(
+         name: project.docker_image_default_repo_prefix + 
"playground-backend-go",
+         root: project.rootProject.hasProperty(["docker-repository-root"]) ?
+               project.rootProject["docker-repository-root"] :
+               project.docker_image_default_repo_root)
+   files "./build/"
+   tags containerImageTags()
+   buildArgs(
+         ['BASE_IMAGE'   : project.rootProject.hasProperty(["base-image"]) ?
+               project.rootProject["base-image"] :
+               "golang:1.18-bullseye",
+          'SDK_TAG'      : project.rootProject.hasProperty(["sdk-tag"]) ?
+                project.rootProject["sdk-tag"] : 
project.rootProject.sdk_version,
+          'SDK_TAG_LOCAL': project.rootProject.sdk_version,
+          'GIT_COMMIT'   : getGitCommitHash(),
+          'GIT_TIMESTAMP': getGitCommitTimestamp()])

Review Comment:
   The risk of wrapping more and more commands with gradle, the difficult it 
will be to troubleshoot in the future.



##########
playground/backend/containers/java/Dockerfile:
##########
@@ -55,6 +57,7 @@ FROM apache/beam_java8_sdk:$BEAM_VERSION
 ARG BEAM_VERSION
 ARG SPRING_VERSION=5.3.25
 ARG KAFKA_CLIENTS_VERSION=2.3.1
+ENV BEAM_VERSION=$BEAM_VERSION

Review Comment:
   We should specify environment variables outside the Docker image using 
ConfigMap



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to