go.temporal.io/server@v1.23.0/common/archiver/util.go (about)

     1  // The MIT License
     2  //
     3  // Copyright (c) 2020 Temporal Technologies Inc.  All rights reserved.
     4  //
     5  // Copyright (c) 2020 Uber Technologies, Inc.
     6  //
     7  // Permission is hereby granted, free of charge, to any person obtaining a copy
     8  // of this software and associated documentation files (the "Software"), to deal
     9  // in the Software without restriction, including without limitation the rights
    10  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    11  // copies of the Software, and to permit persons to whom the Software is
    12  // furnished to do so, subject to the following conditions:
    13  //
    14  // The above copyright notice and this permission notice shall be included in
    15  // all copies or substantial portions of the Software.
    16  //
    17  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    18  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    19  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    20  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    21  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    22  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    23  // THE SOFTWARE.
    24  
    25  package archiver
    26  
    27  import (
    28  	"errors"
    29  
    30  	archiverspb "go.temporal.io/server/api/archiver/v1"
    31  	"go.temporal.io/server/common/log"
    32  	"go.temporal.io/server/common/log/tag"
    33  )
    34  
    35  var (
    36  	errEmptyNamespaceID      = errors.New("field NamespaceId is empty")
    37  	errEmptyNamespace        = errors.New("field Namespace is empty")
    38  	errEmptyWorkflowID       = errors.New("field WorkflowId is empty")
    39  	errEmptyRunID            = errors.New("field RunId is empty")
    40  	errInvalidPageSize       = errors.New("field PageSize should be greater than 0")
    41  	errEmptyWorkflowTypeName = errors.New("field WorkflowTypeName is empty")
    42  	errEmptyStartTime        = errors.New("field StartTime is empty")
    43  	errEmptyCloseTime        = errors.New("field CloseTime is empty")
    44  )
    45  
    46  // TagLoggerWithArchiveHistoryRequestAndURI tags logger with fields in the archive history request and the URI
    47  func TagLoggerWithArchiveHistoryRequestAndURI(logger log.Logger, request *ArchiveHistoryRequest, URI string) log.Logger {
    48  	return log.With(
    49  		logger,
    50  		tag.ShardID(request.ShardID),
    51  		tag.ArchivalRequestNamespaceID(request.NamespaceID),
    52  		tag.ArchivalRequestNamespace(request.Namespace),
    53  		tag.ArchivalRequestWorkflowID(request.WorkflowID),
    54  		tag.ArchivalRequestRunID(request.RunID),
    55  		tag.ArchivalRequestBranchToken(request.BranchToken),
    56  		tag.ArchivalRequestNextEventID(request.NextEventID),
    57  		tag.ArchivalRequestCloseFailoverVersion(request.CloseFailoverVersion),
    58  		tag.ArchivalURI(URI),
    59  	)
    60  }
    61  
    62  // TagLoggerWithArchiveVisibilityRequestAndURI tags logger with fields in the archive visibility request and the URI
    63  func TagLoggerWithArchiveVisibilityRequestAndURI(logger log.Logger, request *archiverspb.VisibilityRecord, URI string) log.Logger {
    64  	return log.With(
    65  		logger,
    66  		tag.ArchivalRequestNamespaceID(request.GetNamespaceId()),
    67  		tag.ArchivalRequestNamespace(request.GetNamespace()),
    68  		tag.ArchivalRequestWorkflowID(request.GetWorkflowId()),
    69  		tag.ArchivalRequestRunID(request.GetRunId()),
    70  		tag.ArchvialRequestWorkflowType(request.GetWorkflowTypeName()),
    71  		tag.ArchivalRequestCloseTimestamp(request.GetCloseTime()),
    72  		tag.ArchivalRequestStatus(request.GetStatus().String()),
    73  		tag.ArchivalURI(URI),
    74  	)
    75  }
    76  
    77  // ValidateHistoryArchiveRequest validates the archive history request
    78  func ValidateHistoryArchiveRequest(request *ArchiveHistoryRequest) error {
    79  	if request.NamespaceID == "" {
    80  		return errEmptyNamespaceID
    81  	}
    82  	if request.WorkflowID == "" {
    83  		return errEmptyWorkflowID
    84  	}
    85  	if request.RunID == "" {
    86  		return errEmptyRunID
    87  	}
    88  	if request.Namespace == "" {
    89  		return errEmptyNamespace
    90  	}
    91  	return nil
    92  }
    93  
    94  // ValidateGetRequest validates the get archived history request
    95  func ValidateGetRequest(request *GetHistoryRequest) error {
    96  	if request.NamespaceID == "" {
    97  		return errEmptyNamespaceID
    98  	}
    99  	if request.WorkflowID == "" {
   100  		return errEmptyWorkflowID
   101  	}
   102  	if request.RunID == "" {
   103  		return errEmptyRunID
   104  	}
   105  	if request.PageSize == 0 {
   106  		return errInvalidPageSize
   107  	}
   108  	return nil
   109  }
   110  
   111  // ValidateVisibilityArchivalRequest validates the archive visibility request
   112  func ValidateVisibilityArchivalRequest(request *archiverspb.VisibilityRecord) error {
   113  	if request.GetNamespaceId() == "" {
   114  		return errEmptyNamespaceID
   115  	}
   116  	if request.GetNamespace() == "" {
   117  		return errEmptyNamespace
   118  	}
   119  	if request.GetWorkflowId() == "" {
   120  		return errEmptyWorkflowID
   121  	}
   122  	if request.GetRunId() == "" {
   123  		return errEmptyRunID
   124  	}
   125  	if request.GetWorkflowTypeName() == "" {
   126  		return errEmptyWorkflowTypeName
   127  	}
   128  	if request.GetStartTime() == nil || request.GetStartTime().AsTime().IsZero() {
   129  		return errEmptyStartTime
   130  	}
   131  	if request.GetCloseTime() == nil || request.GetCloseTime().AsTime().IsZero() {
   132  		return errEmptyCloseTime
   133  	}
   134  	return nil
   135  }
   136  
   137  // ValidateQueryRequest validates the query visibility request
   138  func ValidateQueryRequest(request *QueryVisibilityRequest) error {
   139  	if request.NamespaceID == "" {
   140  		return errEmptyNamespaceID
   141  	}
   142  	if request.PageSize == 0 {
   143  		return errInvalidPageSize
   144  	}
   145  	return nil
   146  }