Git Product home page Git Product logo

Comments (9)

puellanivis avatar puellanivis commented on July 19, 2024

I’m confused a lot by these examples. You seem to be using relative imports (which I have not used at all since we started using go modules), but also you seem to have two separate go.mod files?

from protobuf.

iisharankov avatar iisharankov commented on July 19, 2024

I have a repository where I define the .proto contract, and generate it into Golang among other languages. When pushing these changes, Jenkins builds the golang repo and generates the go.mod you see. So the first block (the contract) and the first go.mod are in a repo where the generated proto files. This I thought was useful as it shows that google.golang.org/protobuf v1.31.0 is a direct dependency and github.com/golang/protobuf v1.5.3 // indirect as an indirect dependency.

The next go.mod file is for a repo that downloads the latest contract version from artifactory, and uses it to actually serialize and send the data. For debugging, I imported "google.golang.org/protobuf/types/known/timestamppb" to see if it is resolved, and it is. provider "subDirectory/provider" is a relative import because it's a package in my repository. It is this package (shown in the next code block, package provider), that imports the contract (line v1 "evaluation/evaluation/v1"), which is at go/pkg/mod/[email protected]/evaluation/v1/evaluation.pb.go. Here the import line timestamppb "google.golang.org/protobuf/types/known/timestamppb" exists, which was auto generated by protobuf, and triggers the error seen in the go build step, stating timestamppb was not resolved since the directory/file was not there, even though it is.

There was a bit of clean up to post this, as well as the error being so strange (lost a few days to it pulling hairs) that it's hard to explain. But put in a sentence: Why is the protobuf auto generated timestamppb "google.golang.org/protobuf/types/known/timestamppb" import failing as unresolved when importing the golang package the contract files are in, even though every other project can resolve timestamppb "google.golang.org/protobuf/types/known/timestamppb" safely. Stranger yet, protoimpl "google.golang.org/protobuf/runtime/protoimpl" is respoved, meaning runetime/protoimpl is discovered, but types/known/timestamppb is not in the protobuf package.

from protobuf.

puellanivis avatar puellanivis commented on July 19, 2024

Is this the complete and total output of the compilation error:

$ go build
# evaluation/evaluation/v1
../../../../../go/pkg/mod/[email protected]/evaluation/v1/evaluation.pb.go:12:14: could not import google.golang.org/protobuf/types/known/timestamppb (open : no such file or directory)

This message oddly suggest something is wrong with your evaluation.pb.go imports and this has nothing to do with timestamppb itself, could you post the first 20-ish or so lines?

from protobuf.

iisharankov avatar iisharankov commented on July 19, 2024

I didn't catch anything odd with the import line there, but sure thing!

evaluation_grpc.pb.go
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc             (unknown)
// source: evaluation/v1/evaluation.proto

package v1

import (
	context "context"
	grpc "google.golang.org/grpc"
	codes "google.golang.org/grpc/codes"
	status "google.golang.org/grpc/status"
)

// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
evaluation.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// 	protoc-gen-go v1.31.0
// 	protoc        (unknown)
// source: evaluation/v1/evaluation.proto

package v1

import (
	protoreflect "google.golang.org/protobuf/reflect/protoreflect"
	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
	timestamppb "google.golang.org/protobuf/types/known/timestamppb"
	reflect "reflect"
	sync "sync"
)

const (
	// Verify that this generated code is sufficiently up-to-date.
	_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
	// Verify that runtime/protoimpl is sufficiently up-to-date.
	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)

from protobuf.

puellanivis avatar puellanivis commented on July 19, 2024

And can you confirm that this was the full output of compilation error?

from protobuf.

iisharankov avatar iisharankov commented on July 19, 2024

Yes. In my personal project running go build gives exactly

$ go build
# evaluation/evaluation/v1
../../../go/pkg/mod/[email protected]/evaluation/v1/evaluation.pb.go:12:14: could not import google.golang.org/protobuf/types/known/timestamppb (open : no such file or directory)

With no other errors

from protobuf.

puellanivis avatar puellanivis commented on July 19, 2024

Hm… this is just so confusing. I’m wondering if it’s possible for you to create a minimal repro, which we would be able to check out and poke around with?

from protobuf.

iisharankov avatar iisharankov commented on July 19, 2024

Sorry for the long delay. Needed some approval to upload things and had to clean the repo, and since then got quite sick for a bit. That time of year. I also worried this was an internal proxy issue and was wasting your time, but I cannot explain how that could be part of it anymore after another two weeks of wrangling with this.

Here's a link to a cleaned up repo of the feature flag system I'm building. Below is a simplified proto file that creates the same issue

evaluation.proto
syntax = "proto3";

package evaluation.v1;

import "google/protobuf/timestamp.proto";

option go_package = "flag-management-system/evaluation/v1";

service FlagManagementSystemService {
  rpc BoolEvaluation(BoolEvaluationRequest) returns (BoolEvaluationResponse) {}
}


// // // // // Base Response // // // // // 

// Response status structure
message ResponseStatus {
  bool success = 1;
  ErrorMessage error = 2;
}


// Error message structure
message ErrorMessage {
  string code = 1;
  string message = 2;
}


// // // // // Base Flag Evaluation // // // // // 

// Extended evaluation request to include more types
message EvaluationRequest {
  string flag_path = 1;
  EvaluationContext context = 10; // Possible addition of evaluation context?
}


// Response structure for different types of feature flags
message EvaluationResponse {
  string flag_path = 1;
  ResponseStatus status = 5;
}




// // // // // Bool Flag Evaluation // // // // // 

// Boolean flags request
message BoolEvaluationRequest {
  uint32 batch_size = 1;
  repeated EvaluationRequest requests = 10;
}


// Single Boolean flag response
message BoolSingleFlagResponse {
  bool value = 1;
  EvaluationResponse metadata = 5;
}


// Boolean flags response
message BoolEvaluationResponse {
  uint32 response_size = 1;
  repeated BoolSingleFlagResponse results = 10;
}




// // // // // Context Evaluation  // // // // // 

// Provider Context 
message EvaluationContext {

  // Provider-specific information
  string provider_id = 1;
  string provider_has = 2;
  
  // Environmental and temporal data
  google.protobuf.Timestamp request_time = 3; 
  string request_time_zone = 4;
  string provider_language = 5;
  string provider_version = 6;
}

And the relevant part of the buf.gen.yaml

buf.gen.yaml
version: v1
plugins:
  # Go
  - plugin: buf.build/protocolbuffers/go
    out: gen/go
    opt:
      - paths=source_relative
  - plugin: buf.build/grpc/go
    out: gen/go
    opt:
      - paths=source_relative

As said before, when this is generated with buf generate, I then go build and deploy via Jenkins to Artifactory (not included) so it can be downloaded and sourced by users. The repo shared has a provider that should download the protobuf files from artifactory (note the modification to GONOSUMDB). For a while I've worried this is an issue on the internal proxy and artifactory and not with protobuf, but I've continued going in circles for days, and can't understand why runetime/protoimpl is discovered, but types/known/timestamppb is not, as mentioned before. Let me know if there's anything more I can provide.

from protobuf.

puellanivis avatar puellanivis commented on July 19, 2024

I checked out your repo, but I get an issue with REDACTED.com/[email protected]: malformed module path "REDACTED.com/evaluation": invalid char 'R' in first path element"

Removing this line from the go.mod I get main.go:8:2: package openfeature-provider-golang/provider is not in std (/usr/local/go/src/openfeature-provider-golang/provider

from protobuf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.